{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture 11_0 - CS193p Spring 2010 Thursday May 6 2010 Today...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
CS193p Spring 2010 Thursday, May 6, 2010
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Today: Persistence Property Lists Archiving Objects Storing things in the filesystem SQLite Core Data Thursday, May 6, 2010
Background image of page 2
Property Lists Any combination of the following classes NSArray NSDictionary NSString NSData NSDate NSNumber Great for storing small amounts of information Three different persistent formats XML Binary “Old-Style” ASCII (deprecated) Thursday, May 6, 2010
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Property Lists NSPropertyListSerialization + (NSData *)dataFromPropertyList:(id) plist format:(NSPropertyListFormat) format errorDescription:(NSString **) errorString; The format is either XML or Binary The errorDescription is (somewhat) human-readable ( nil if no error) + (id)propertyListFromData:(NSData *)data mutabilityOption:(NSPropertyListMutabilityOptions)opt format:(NSPropertyListFormat *)format errorDescription:(NSString **)errorString; The mutabilityOption is immutable, mutable containers, or all mutable + (BOOL)propertyList:(id)plist isValidForFormat:(NSPropertyListFormat)format; Thursday, May 6, 2010
Background image of page 4
Property Lists But there are much simpler versions If the top level of your property list is an array or dictionary (which it almost always is). NSArray - (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag; If flag is YES , then it writes to temporary file, deletes old, moves to new. Writes it in XML format (not binary format). + (NSArray *)arrayWithContentsOfFile:(NSString *)path; - initWithContentsOfFile:(NSString *)path; Note that these create immutable arrays. Can mutableCopy or use binary property list format to get mutability. NSDictionary + (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag; + (NSDictionary *)dictionaryWithContentsOfFile:(NSString *)path; Thursday, May 6, 2010
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Property Lists To write to a file in binary format Use NSPropertyListSerialization , then NSData ’s writeToFile:atomically: Thursday, May 6, 2010
Background image of page 6
Property Lists What does the XML version look like? Here’s a fragment of the equations.plist from last week <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd "> <plist version="1.0"> <dict> <key>y = 0.5x</key> <array> <real>0.5</real> <string>*</string> <string>@x</string> <string>=</string> </array> </dict> </plist> Thursday, May 6, 2010
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
JSON JavaScript Object Notation Here’s a sample of it from a Flickr fetch. It contains a single dictionary (photos) with some keys (page, pages, etc.), one of which (photo) is an array of dictionaries. <photos page="2" pages="89" perpage="10" total=”881”> < photo id="2636" owner="[email protected] secret="a123456" server="2" title="test_04” ispublic="1" isfriend="0" isfamily="0" /> <photo id="2635" owner="[email protected] secret="b123456" server="2" title="test_03” ispublic="0" isfriend="1" isfamily="1" /> <photo id="2610" owner="[email protected] secret="d123456" server="2" title="00_tall” ispublic="1" isfriend="0" isfamily="0" /> </photos> FlickrFetcher uses a JSON conversion library downloaded from the web.
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}