我以爲可以通過使用value:withObjCType:
來使用NSValue。但根據文檔變長的類型不能使用。
The type you specify must be of constant length. You cannot store C strings, variable-length arrays and structures, and other data types of indeterminate length in an NSValue—you should use NSString or NSData objects for these types.
假設這樣的:
//Sample data
typedef struct {
CGFloat lat;
CGFloat longi;
}Location;
Location list[2];
Location get[2];
Location l1;
l1.lat = 10.0;
l1.longi = 4.0;
Location l2;
l2.lat = 3.0;
l2.longi = 4.0f;
list[0] = l1;
list[1] = l2;
您可以使用NSData
通過以下方式爲您的要求:
//This is the part you want
//create NSData
NSData *data = [NSData dataWithBytes:list length:sizeof(list)];
//get c array from NSData
[data getBytes:&get length:sizeof(list)];
//accessing
methodUsingCarray(getList);
NSLog(@"%f",get[0].lat); // only if you need to access individual points
希望它能幫助。
這是爲什麼被低估? – 2013-07-18 18:47:49
嘗試使用CoreData。這是堅持大量數據的最佳方式。有很多關於如何在Internet上使用CoreData的例子。 –
你可以寫一個值轉換器。不知道它是否會產生相同的性能。可以檢查出來。 – Rakesh