开发者

Writing to file multi dimensional NSMutableArray problems

开发者 https://www.devze.com 2023-03-12 21:56 出处:网络
I am having trouble writing and retrieving a multidimensional array from a file. I add all the objects I want to write into an array and write and retrieve the array from a file it creates. All of the

I am having trouble writing and retrieving a multidimensional array from a file. I add all the objects I want to write into an array and write and retrieve the array from a file it creates. All of the other objects beside the multidimensional array are reading and writing properly except for the multidimensional NSMutable array Object.

I writing the array using:

[array addObject:multiDiminutionalArray];
[array writeToFile:[self dataFilePath] atomically:YES];

I read the array using:

NSMutableArray *array = [[NS开发者_StackOverflow中文版MutableArray alloc] initWithContentsOfFile:filePath];
multiDiminutionalArray = [array objectAtIndex:1];

Any ideas?


YuzaKen should've made the comment into an answer.

I suspect lack of NSCoding conformance for the class(es) of one or more of the objects stored in your array is the issue. NSArray knows how to archive itself but do the objects stored in it?

Alternatively, make sure your file path is a valid file path. If it's something like @"myFile.dat" it's not valid because it's not a full path. If it's something like @"~/Desktop/myFile.dat" it's also not valid because the tilde isn't expanded to the full /Users/me/... path.

0

精彩评论

暂无评论...
验证码 换一张
取 消