سؤال

I have to convert an NSNumber to CLLocationDistance for comparing them. So are there any formatter to do that? I searched at internet but i could not find.

هل كانت مفيدة؟

المحلول

CLLocationDistance is really just a double. All you need is this:

NSNumber *number = ... // some number
CLLocationDistance distance = ... // some distance

if (distance == [number doubleValue]) {
    // they are equal
}

Keep in mind that comparing two double values for equality can appear to fail due to the inexactness of most double values.

if (abs(distance - [number doubleValue]) <= DBL_EPSILON) {
    // they are equal
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top