0

i need to write a string to my plist, but a can't find plist, why?

in .h

NSMutableDictionary *cameras;

.m file

#define DOCUMENTS [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]

in ViewDidLoad

NSString *plistPath = [DOCUMENTS stringByAppendingPathComponent:@"Сamera.plist"];
    if([[NSFileManager defaultManager] fileExistsAtPath:plistPath])
    {
        NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
        cameras = [NSMutableDictionary dictionaryWithDictionary:[NSPropertyListSerialization propertyListFromData:plistXML mutabilityOption:NSPropertyListMutableContainersAndLeaves format:nil errorDescription:nil]];
    }
Roman Simenok
  • 530
  • 7
  • 22
  • usually it is set to `[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]` instead of using lastObject. Maybe that has something to do with it... – Daniel Aug 14 '13 at 13:58
  • Try [listing all files](http://stackoverflow.com/questions/7900879/how-to-list-all-folders-and-their-subdirectories-files-in-iphone-sdk/7900946#7900946) to see if it's in the right place – Daniel Aug 14 '13 at 14:02
  • Did you remember to add it in Xcode? – Kevin Aug 14 '13 at 14:14

2 Answers2

2
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *docDirPath = [documentsDirectory stringByAppendingPathComponent:@"YourPlist.plist"];

NSFileManager *fileManager = [NSFileManager defaultManager];

if(![fileManager fileExistsAtPath: docDirPath]) {
    NSString *bundle = [[NSBundle mainBundle] pathForResource:@"YourPlist" ofType:@"plist"];

    [fileManager copyItemAtPath:bundle toPath:docDirPath error:&error];

    NSLog(@"plist is copied to Directory");
 }

Make sure your directory contains the plist file.

Nabeel Thobani
  • 939
  • 10
  • 23
1

// Do this instead:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *plistPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Сamera.plist"];
Puneet Sharma
  • 9,369
  • 1
  • 27
  • 33
  • [NSPathStore2 objectAtIndex:]: unrecognized selector sent to instance 0x76cda20 2013-08-14 20:03:19.145 EHControl[1802:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSPathStore2 objectAtIndex:]: unrecognized selector sent to instance 0x76cda20' SIGABRT – Roman Simenok Aug 14 '13 at 14:04
  • After edit it compiles but still can't find, it finds other plist's but not my =/ – Roman Simenok Aug 14 '13 at 14:17
  • If you are testing on simulator, Open your app's sandbox following these steps: Finder -> Go to folder -> ~/library -> Application Support -> iPhone Simulator -> 6.1- > Applications -> "Find out your app" -> Documents and see whether your Camera.pLIst file exists there or not. – Puneet Sharma Aug 14 '13 at 14:18