开发者

Filtering elements while reading .plist array into NSArray

First post - hope I'm doing it right!

I have a file, lexicon.plist, containing an array of about 250K words. I want to load all words of length 'n' into an NSArray.

I know about the NSArray instance method:

  • (id)initWithContentsOfFile:(NSString *)aPath

but I don't see any way to intervene in the process of reading the file into the NSArray. The only solution I can see is to first load the entire lexicon into one NSArray, and then run through it in a loop selecting the elements of length 'n'.

I'm very new at Cocoa, but I have come across some methods that perform some sort of iterative task, that accept a "block" of code that is invoked at each iteration. I was wondering if such a functional variant of initWithContentsOfFile might exist, o开发者_如何学Cr how else I might iteratively read an array from a .plist file and filter the elements I'm interested in.

[And if you're wondering if this might be a case of premature optimization - it is ;-) But I'd still like to know.]


.plist files are basically XML files so you can use an NSXMLParser on it and filter out the elements of interest.


If you want to load a filtered selection of a saved data, you should use a SQL repository using SQLite, for example. Plain files can only be fully loaded in memory.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜