我有一个数组这样的:CGPoint array[1000]
(I加触摸的位置进入这个数组)。问题是我想将此数组保存到文档目录中的文本文件中,并检索它。有人能帮忙吗?CGpoint阵列写入到文本文件
感谢所有
我有一个数组这样的:CGPoint array[1000]
(I加触摸的位置进入这个数组)。问题是我想将此数组保存到文档目录中的文本文件中,并检索它。有人能帮忙吗?CGpoint阵列写入到文本文件
感谢所有
而不是使用一个普通的C数组的,我会建议您使用NSArray
存储您CGPoints的集合。由于NSArray
符合NSCoding
协议,可以序列并从文件反序列化。您应该阅读Archives and Serializations Programming Guide。
编辑下面是一个例子:
// 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];
你的问题被错误地被格式化为一个代码。你能修好它吗? –
我的问题是我们可以存储一个Cgpointsarray到文本文件.. ?? – userar
是的,我明白你的问题(尽管你可以说得更清楚)。我对你的整个问题提出了一个问题,它被错误地格式化为_code_。 –