Skip to content

Instantly share code, notes, and snippets.

@hartbit
Last active June 16, 2016 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hartbit/07b5684814e2adc2d0185138465a60b4 to your computer and use it in GitHub Desktop.
Save hartbit/07b5684814e2adc2d0185138465a60b4 to your computer and use it in GitHub Desktop.
Proposed naming changes to Framework APIs to conform to Swift Design Guidelines

CoreMotion

CMMotionActivityManager

Two modifications here:

  • Remove the starting suffix as it only really pertains to the first argument.
  • Rename the queue label to on to reduce the ambiguity from using two label with the same name (to).
- public func queryActivityStarting(from start: Date, to end: Date, to queue: OperationQueue, withHandler handler: CoreMotion.CMMotionActivityQueryHandler)
+ public func queryActivity(from start: Date, to end: Date, on queue: OperationQueue, withHandler handler: CoreMotion.CMMotionActivityQueryHandler)

Change to mirror the label change on CMMotionActivityManager.queryActivityStarting(from:to:to:withHandler:):

- public func startActivityUpdates(to queue: OperationQueue, withHandler handler: CoreMotion.CMMotionActivityHandler)
+ public func startActivityUpdates(on queue: OperationQueue, withHandler handler: CoreMotion.CMMotionActivityHandler)

CMMotionManager

Changes to mirror the label change on CMMotionActivityManager.queryActivityStarting(from:to:to:withHandler:):

- public func startAccelerometerUpdates(to queue: OperationQueue, withHandler handler: CoreMotion.CMAccelerometerHandler)
+ public func startAccelerometerUpdates(on queue: OperationQueue, withHandler handler: CoreMotion.CMAccelerometerHandler)
...
- public func startGyroUpdates(to queue: OperationQueue, withHandler handler: CoreMotion.CMGyroHandler)
+ public func startGyroUpdates(on queue: OperationQueue, withHandler handler: CoreMotion.CMGyroHandler)
...
- public func startMagnetometerUpdates(to queue: OperationQueue, withHandler handler: CoreMotion.CMMagnetometerHandler)
+ public func startMagnetometerUpdates(on queue: OperationQueue, withHandler handler: CoreMotion.CMMagnetometerHandler)
...
- public func startDeviceMotionUpdates(to queue: OperationQueue, withHandler handler: CoreMotion.CMDeviceMotionHandler)
+ public func startDeviceMotionUpdates(on queue: OperationQueue, withHandler handler: CoreMotion.CMDeviceMotionHandler)

CMAltimeter

Change to mirror the label change on CMMotionActivityManager.queryActivityStarting(from:to:to:withHandler:):

- public func startRelativeAltitudeUpdates(to queue: OperationQueue, withHandler handler: CoreMotion.CMAltitudeHandler) {
+ public func startRelativeAltitudeUpdates(on queue: OperationQueue, withHandler handler: CoreMotion.CMAltitudeHandler) {

CMStepCounter

Change to mirror the label change on CMMotionActivityManager.queryActivityStarting(from:to:to:withHandler:):

- public func queryStepCountStarting(from start: Date, to end: Date, to queue: OperationQueue, withHandler handler: CoreMotion.CMStepQueryHandler)
+ public func queryStepCountStarting(from start: Date, to end: Date, on queue: OperationQueue, withHandler handler: CoreMotion.CMStepQueryHandler)

The following method has two changes:

  • Change to mirror the label change on CMMotionActivityManager.queryActivityStarting(from:to:to:withHandler:)
  • The updateOn is fairly unclear as use site.
- public func startStepCountingUpdates(to queue: OperationQueue, updateOn stepCounts: Int, withHandler handler: CoreMotion.CMStepUpdateHandler)
+ public func startStepCountingUpdates(on queue: OperationQueue, updateOnStepCounts stepCounts: Int, withHandler handler: CoreMotion.CMStepUpdateHandler)

CMMagneticFieldCalibrationAccuracy

The type is better represented as an enum.

- public struct CMMagneticFieldCalibrationAccuracy : RawRepresentable, Equatable {
-     public init(_ rawValue: Int32)
-     public init(rawValue: Int32)
-     public var rawValue: Int32
- }
- public var CMMagneticFieldCalibrationAccuracyUncalibrated: CMMagneticFieldCalibrationAccuracy { get }
- public var CMMagneticFieldCalibrationAccuracyLow: CMMagneticFieldCalibrationAccuracy { get }
- public var CMMagneticFieldCalibrationAccuracyMedium: CMMagneticFieldCalibrationAccuracy { get }
- public var CMMagneticFieldCalibrationAccuracyHigh: CMMagneticFieldCalibrationAccuracy { get }
+ public enum CMMagneticFieldCalibrationAccuracy: Int32 {
+     case uncalibrated = -1,
+     case low
+     case medium
+     case high
+ }

CMError

The type is better represented as an enum conforming to ErrorProtocol:

- public struct CMError : RawRepresentable, Equatable {
-     public init(_ rawValue: UInt32)
-     public init(rawValue: UInt32)
-     public var rawValue: UInt32
- }
- public var CMErrorNULL: CMError { get }
- public var CMErrorDeviceRequiresMovement: CMError { get }
- public var CMErrorTrueNorthNotAvailable: CMError { get }
- public var CMErrorUnknown: CMError { get }
- public var CMErrorMotionActivityNotAvailable: CMError { get }
- public var CMErrorMotionActivityNotAuthorized: CMError { get }
- public var CMErrorMotionActivityNotEntitled: CMError { get }
- public var CMErrorInvalidParameter: CMError { get }
- public var CMErrorInvalidAction: CMError { get }
- public var CMErrorNotAvailable: CMError { get }
- public var CMErrorNotEntitled: CMError { get }
- public var CMErrorNotAuthorized: CMError { get }
+ public enum CMError : UInt32, ErrorProtocol {
+     case null
+     case requiresMovement
+     case trueNorthNotAvailable
+     case unknown
+     case activityNotAvailable
+     case activityNotAuthorized
+     case activityNotEntitled
+     case invalidParameter
+     case invalidAction
+     case notAvailable
+     case notEntitled
+     case notAuthorized
+ }

CMMotionActivity

Boolean methods and properties that should read as assertions:

- public var unknown: Bool { get }
+ public var isUnknown: Bool { get }
...
- public var stationary: Bool { get }
+ public var isStationary: Bool { get }
...
- public var walking: Bool { get }
+ public var isWalking: Bool { get }
...
- public var running: Bool { get }
+ public var isRunning: Bool { get }
...
- public var automotive: Bool { get }
+ public var isAutomotive: Bool { get }
...
- public var cycling: Bool { get }
+ public var isCycling: Bool { get }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment