plist or text file
Hi I have to create a table with some data. For the data, I read online that you can create a plist. But I 开发者_StackOverflowwasn't sure how it worked? Does it only work in navigation based? I created a view based app, and used a text file instead, and then read from the file into an array which loads the data to my table. It works fine. But I'm just curious when/why/how would you use plists? I am programming in iOS for iPhone.
Plists are a special kind of XML. They are easy to create in Xcode and can all sorts of data types including strings, numbers, and booleans. It can organize those items into dictionaries and or arrays. They are always the best route for small or medium amounts of data. And they can be used anywhere.
Plists are great, mostly because they're invisible if you just want to archive some standard Cocoa data structures/holders (NSArray
,NSDictionary
,NSString
,NSNumber
, etc...) to a file and back out again without missing a beat.
IMHO, the simplest use for plists is the writeToFile:atomically:
method on NSDictionary
, and the corresponding initWithContentsOfFile:
. These let you store your (relatively primitive) data in an ad-hoc plist, without even having to know that's what it will be stored as.
精彩评论