Вместо использования простого массива C я бы порекомендовал использовать NSArray
для хранения вашей коллекции CGPoints.Поскольку NSArray
соответствует протоколу NSCoding
, вы можете сериализовать и десериализовать его из файла.
Вы должны прочитать Руководство по программированию архивов и сериализаций .
РЕДАКТИРОВАТЬ Вот пример:
// Create an NSMutableArray
NSMutableArray *points = [[NSMutableArray alloc] init];
// Add a point to the array
// Read up on NSValue objects to understand why you simply cannot add a C
// struct like CGPoint to the array
[points addObject:[NSValue valueWithBytes:&point1 objCType:@encode(CGPoint)]];
// archive the array -- this will store the array in a file
BOOL result = [NSKeyedArchiver archiveRootObject:points toFile:filePath];
NSLog(@"Archival result: %d", result);
// unarchive the array -- this will retrieve your array from the file
NSMutableArray *points2 = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];