Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get data from property list from Documents?

I’m new to the Objective-C

I want to read a file.plist from path Documents:

/4BC1E3AF-15AD-4F33-A55D-E52C60F13DE8/data/Containers/Data/Application/95BD9BE3-5A5A-4EAC-A9FE-133EF64D1D1A/Documents"

Can you help me replace this line of code?:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

NSDictionary *dictRoot = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"TestPlist" ofType:@"plist"]];

Full code:
here

>Solution :

You get the URL of the Documents folder in the container with

NSURL *documentsFolderURL = [[NSFileManager defaultManager]
                             URLForDirectory: NSDocumentDirectory
                             inDomain: NSUserDomainMask
                             appropriateForURL: nil
                             create: false
                             error: nil];

NSDictionary *dictRoot = [NSDictionary dictionaryWithContentsOfURL:[documentsFolderURL URLByAppendingPathComponent:@"TestPlist.plist"] error: nil];

There is also dictionaryWithContentsOfURL although I recommend to prefer NSPropertyListSerializtion

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading