• Home
  • Basics
  • DSA
  • MAD
  • Concept
  • Practice
  • Misc
    • Tips
    • QA’s
    • Misc
  • Course
  • Home
  • Basics
  • DSA
  • MAD
  • Concept
  • Practice
  • Misc
    • Tips
    • QA’s
    • Misc
  • Course
  • #News
  • #APPS
  • #Apple WWDC
  • #Google I/O
  • #Microsoft Ignite
  • #Let’s Talk
  • #Advertise

MyCodeTips mycodetips-newlogocopy1

  • Home
  • Basics
  • DSA
  • MAD
  • Concept
  • Practice
  • Misc
    • Tips
    • QA’s
    • Misc
  • Course
IOS

How to read data from property list file (.plist) to NSDictionary in IOS.

Read data from property list

- (NSDictionary *) dictionaryWithPropertyListAtPath: (NSString *) path {
NSString *error = nil; 
NSPropertyListFormat format; 

NSData *plistXML = [ [NSFileManager defaultManager] contentsAtPath: path];
NSDictionary *result = (NSDictionary *) [NSPropertyListSerialization propertyListFromData: plistXML 
mutabilityOption: NSPropertyListMutableContainersAndLeaves 
format: &format 
errorDescription: &error];
if (error != nil) {
NSLog(@"Error while reading plist: %@", error);
}
return result;
}

- (void) saveDictionary: (NSDictionary *) dictionary toPropertyListAtPath: (NSString *) path {
NSString *error = nil;

NSData *plistData = [NSPropertyListSerialization dataFromPropertyList: dictionary
format: NSPropertyListXMLFormat_v1_0
errorDescription: &error];

if (plistData != nil) {
[plistData writeToFile: path atomically: YES];
} else {
NSLog(@"Error while writing plist: %@", error);
}
}
Written by Ranjan - April 17, 2015 - 1760 Views
AUTHOR
Ranjan

This website is basically about of what we learnt from my years of experience as a software engineer on software development specifically on mobile application development, design patterns/architectures and its changing scenarios, security, troubleshooting, tools, tips&tricks and many more.

Next Post
Previous Post

Support us

  • Exploring Single Point Failures: Causes and Impacts
  • Exploring the Pros and Cons of Primitive Data Types
  • Essential Coding Standards and Best Practices for Clean Code
  • What Business Problems Solves in Low Level Design (LLD)
  • SRP : Single Responsibility Principle in Swift and Objective-C
whiteboard

Whiteboard(PRO)

whiteboard

Whiteboard(lite)

alphabets

Kids Alphabet

do2day

Do2Day

MyCodeTips

©mycodetips.com