2013-03-01 61 views
0

AM嘗試將CLLocationCoordinate2D []添加到NSMutableArray並將其作爲參數發送。但(__bridge id)正在崩潰應用程序。結構到id轉換是個問題。任何人都可以請讓我知道如何使用這個請。如何使用網橋CLLocationCoordinate2D

CLLocationCoordinate2D coordinates [1000];

coordinates [index] ---在循環中添加的所有座標。

NSMutableArray *coorArray = [NSMutableArray array]; 
[coorArray addObject:(__bridge id)(coordinates)]; crashes here 
+0

如果我理解正確,你想創建一個CLLocationCoordinate2D數組的數組? – Rikkles 2013-03-01 10:46:49

+0

是的,你是正確的 – Manoj 2013-03-01 10:49:09

回答

1

用途:

NSMutableArray *coorArray = [NSMutableArray array]; 
[coorArray addObject:[NSValue valueWithPointer:coordinates]]; 

然後,當你想要檢索結構的陣列:

CLLocationCoordinate2D coordinates[] = [coorArray objectAtIndex:0].pointerValue; 

AC陣列不是一個物體,所以它不能被橋接。

1

你應該看看+[NSValue valueWithBytes:objCType:]不是一個(__bridge)演員。橋是爲了其他的事情。

如: [NSValue value:&coordinate withObjCType:@encode(CLLocationCoordinate2D)];

我想這是可能的編碼整個陣列太

+0

否在這種情況下,座標是一個CLLocationCoordinate2D數組。 – Rikkles 2013-03-01 10:54:31

+0

我接受Rikkles的回答,因爲它正是我想要的。我仍然應該給你一個幫助你的努力。謝謝。 – Manoj 2013-03-01 11:51:45