Я сохраняю два CGPoints (в массиве) в текстовый файл в каталоге Documents. Когда я прочитал файл, это то, что я получаю:Чтение NSPoint из текстового файла
NSPoint: {66.5, 87}, NSPoint: {198.5, 314.5}
Как получить такой вывод:
66.5 87
198.5 314.5
Вот мой код:
//save the coordinates of two points into a text file in the Documents directory
- (void)savePoints
{
//get Document directory's path
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"POINTS.txt"];
//create an points array
NSMutableArray *points = [[NSMutableArray alloc] init];
[points addObject:[NSValue valueWithBytes:&fromPoint objCType:@encode(CGPoint)]]; //insert object at the end of the array
[points addObject:[NSValue valueWithBytes:&toPoint objCType:@encode(CGPoint)]];
//write points array to file
BOOL result = [NSKeyedArchiver archiveRootObject:points toFile:fullPath];
NSLog(@"Archival result: %d", result);
}
//read the file
-(void)getPoints
{
//get Document directory's path
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"POINTS.txt"];
//read points array from file
NSMutableArray *points = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
NSString *str = [points componentsJoinedByString:@","];
NSLog(@"%@", str);
}
Может у объяснить ур вопрос немного .. У-у нужно преобразовать строку в CGPoint? – Dany