iOS: Objectifying MKCoordinateSpan to put in an array

243 views Asked by At

Im trying to find a direct way to put MKCoordinateSpan into an array without breaking it down to lat and long and store it in an NSArray. Not sure if there is such way.

2

There are 2 answers

1
Sergey Kalinichenko On BEST ANSWER

Try this:

MKCoordinateSpan currentSpan;
currentSpan = ...; // Set the span to somethinf
NSValue *spanVal = [NSValue valueWithBytes:&currentSpan objCType:@encode(MKCoordinateSpan)];
...
MKCoordinateSpan currentSpanBack;
[spanVal getValue:&currentSpanBack];
1
Jano On
MKCoordinateSpan span = MKCoordinateSpanMake(1.0, 1.0);
NSData *data = [NSData dataWithBytes:&span length:sizeof(span)];

MKCoordinateSpan back;
[data getBytes:&back length:sizeof(back)];

NSLog(@"%f",back.latitudeDelta);