How to read data structure from .plist file into NSArray

NSString* plistPath = [[NSBundle mainBundle] pathForResource:@”league” ofType:@”plist”]; contentDict = [NSDictionary dictionaryWithContentsOfFile:plistPath]; That answer is correct – are you sure that your file is in the app? Did you add it to your project, and check to see if it gets copied into your app bundle? If not, it might be the file was not added … Read more

Save Data to .plist File in Swift

Apparently the file is not in a writable location, so I created it in the documents directory. var paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String var path = paths.stringByAppendingPathComponent(“data.plist”) var fileManager = NSFileManager.defaultManager() if (!(fileManager.fileExistsAtPath(path))) { var bundle : NSString = NSBundle.mainBundle().pathForResource(“data”, ofType: “plist”) fileManager.copyItemAtPath(bundle, toPath: path, error:nil) } data.setObject(object, forKey: “object”) data.writeToFile(path, atomically: true) … Read more

Working with data in iOS Apps (What to choose? NSData, CoreData, sqlite, PList, NSUserDefaults)

You can use these rules of thumb to decide what storage model will work for your app. If the data fits in memory entirely and is relatively unstructured, use plist If the data fits in memory entirely and has tree-like structure, use XML If the data does not fit in memory and has a structure … Read more

Parse Plist (NSString) into NSDictionary

See Serializing a Property List NSData* plistData = [source dataUsingEncoding:NSUTF8StringEncoding]; NSString *error; NSPropertyListFormat format; NSDictionary* plist = [NSPropertyListSerialization propertyListWithData:plistData mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&error]; NSLog( @”plist is %@”, plist ); if(!plist){ NSLog(@”Error: %@”,error); [error release]; }