Can not find plist file in documents directory? How to modify the plist programmatically?

前端 未结 1 634
鱼传尺愫
鱼传尺愫 2021-01-06 17:59

I have an application in Xcode 4.2.

I have created plist file as my requirement.

I have found the data from Applications main bundle and got the data in to t

相关标签:
1条回答
  • 2021-01-06 18:38

    you need to copy plist from bundle to document directory first

    -(void) checkAndCreateSetting
    {
        BOOL success;
        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSError *error;
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *writableDBPath= [documentsDirectory stringByAppendingPathComponent:@"Settings.plist"];
        success = [fileManager fileExistsAtPath:writableDBPath];
        if (success) return;
        // The writable database does not exist, so copy the default to the appropriate location.
        NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Settings.plist"];
        success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
        if (!success) {
            NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
        }
    }
    

    let me know in case of any query thanks& regards neil

    0 讨论(0)
提交回复
热议问题