Skip to content

Instantly share code, notes, and snippets.

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 jonfriskics/df62d546d51ea7970ca8 to your computer and use it in GitHub Desktop.
Save jonfriskics/df62d546d51ea7970ca8 to your computer and use it in GitHub Desktop.
extension CLLocationCoordinate2D: Equatable {}
extension Double {
func places(p: Double) -> String {
return NSString(format: "%\(p)f", self)
}
}
public func ==(lhs: CLLocationCoordinate2D, rhs: CLLocationCoordinate2D) -> Bool {
return lhs.latitude.places(3) == rhs.latitude.places(3) && lhs.longitude.places(3) == rhs.longitude.places(3)
}
@jonfriskics
Copy link
Author

as opposed to this in Objective-C/C

#define kAccuracy (0.0001)

static BOOL doubleCloseTo(double a, double b){
    if (fabs(a-b) < kAccuracy) {
        return YES;
    } else {
        return NO;
    }
}

double expectedLat = 28.418710;
// observedLat comes from a returned CLLocationCoordinate2D

XCAssert(doubleCloseTo(expectedLat, observedLat), @"Latitudes don't match");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment