开发者

Objective C - Populate Array From Exceedingly large PList

开发者 https://www.devze.com 2023-03-14 03:28 出处:网络
I am having some trouble populating a large plist into an array. Here is the snippet of code giving me problems:

I am having some trouble populating a large plist into an array. Here is the snippet of code giving me problems:

// Populate the routes.
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"routes" ofType:@"plist"];
NSMutableArray *routes = [NSMutableArray arrayWithContentsOfFile:filePat开发者_如何学Goh];
NSLog(@"Routes: %@", routes);

// Populate the trips.
NSString *filePath2 = [[NSBundle mainBundle] pathForResource:@"trips" ofType:@"plist"];
NSMutableArray *trips = [NSMutableArray arrayWithContentsOfFile:filePath2];
NSLog(@"Trips: %@", trips);

My issue is that after displaying each mutable array in the logs, the log for the routes array displays just fine, but the log for the trips array simply doesn't appear at all. Usually when an issue occurs then the log will show something like "Trips: ( )", but that line doesn't appear at all in this case. The only difference I can see between the two instances is that the routes plist is an array with about 1000 dictionary objects and the trips plist has nearly 92,000 objects. Is there some sort of limit on the size of plists?

Thanks in advance.


"Is there some sort of limit on the size of plists?"

There isn't a limit to to the size of plists, but there is a limit to the amount of data that you can feed to an NSLog() command.

If trips were actually nil, the NSLog() call would succeed, and simply print out (null). The trips array is populated, however, which is why it's not printing out at all: NSLog() is saying, "sorry, there's no way I'm going to let you to print out all that".

I believe this has likely changed in more recent versions of OS X due to possible security concerns or performance issues. (In the past, users' hard drives would fill up with log files that were GB in size, caused by one process logging an error message hundreds of times a second; that is now limited to 500 logs per second). It's kind of confusing why nothing is printed out and you get no feedback from Xcode or anything, but I guess the system has no way of knowing whether your use of NSLog() is with good intentions or not.


According to the doc, if there is a parse problem or there is an issue with opening the file, nil will be returned. Is it possible in that massive file there is a bad character or a typo that might break the xml?

" Return Value --> An array containing the contents of the file specified by aPath. Returns nil if the file can’t be opened or if the contents of the file can’t be parsed into an array.

0

精彩评论

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