Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 9. Working with Property Lists > Reading Data from Property Lists

Reading Data from Property Lists

From: readplist.m

 6 NSArray *array =
 7   [NSArray arrayWithContentsOfFile:
 8     @"example.plist"];
 9 NSData *data = [NSData dataWithContentsOfFile:
10   @"example.plist"];
11 NSMutableArray *mutable =
12   [NSPropertyListSerialization
13     propertyListFromData: data
14         mutabilityOption:
15   NSPropertyListMutableContainersAndLeaves
16                   format: NULL
17         errorDescription: NULL];
18 NSCAssert([mutable isKindOfClass:
19     [NSMutableArray class]],
20   @"Should have read a mutable array");
21 [[mutable objectAtIndex: 0]
22   appendString: @"suffix"];

There are two ways of reading in a property list. The first is to use the inverse of the method that we just looked at for writing them. Both of the collection classes that support property list serialization have an -initWithContentsOfFile: initializer, as well as a corresponding constructor.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial