Lecture 11_0

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

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS193p Spring 2010 Thursday, May 6, 2010 Today: Persistence Property Lists Archiving Objects Storing things in the flesystem SQLite Core Data Thursday, May 6, 2010 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 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 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 Fle, 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 Property Lists To write to a fle in binary Format Use NSPropertyListSerialization , then NSData ’s writeToFile:atomically: Thursday, May 6, 2010 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 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...
View Full Document

This note was uploaded on 02/15/2011 for the course CS 193P taught by Professor Evandoll during the Spring '09 term at Stanford.

Page1 / 46

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

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online