Question

I'm having a problem I can not solve: I have the following Array in plist:

//userSettings.plist
<plist version="1.0">
<array>
    <integer>2</integer>
    <string>4</string>
    <integer>0</integer>
    <integer>1</integer>
</array>
</plist>

And I'm trying to load as follows:

    NSString *settingsDataPath = [[self docsDir]stringByAppendingPathComponent:@"userSettings.plist"];
    if (![[NSFileManager defaultManager]fileExistsAtPath:settingsDataPath]) {
        [[NSFileManager defaultManager]copyItemAtPath:[[NSBundle mainBundle] pathForResource:@"userSettings" ofType:@"plist"] toPath:settingsDataPath error:&error];
    }

    BOOL success = [[NSFileManager defaultManager] fileExistsAtPath:settingsDataPath];
    NSLog(@"%hhd", success);

    userSettings = [NSArray arrayWithContentsOfFile:settingsDataPath];
    NSLog(@"%d", [userSettings count]);

The Success boolean is returning TRUE, but when I do a NSLog of [userSettings count], my result is always 0, ie, my array is always empty ...

I do not know what else I can do...

Ty guys!!!

Was it helpful?

Solution

I found the error guys. The problem is that when I created the plist for the first time in the interface builder, created as a Dictionary ... Only after I moved to Array. The problem is that the plist that was stored internally in the application, have not updated. When I deleted this plist, everything worked as it should!

Thanks for the help everyone!

Before modifications enter image description here

After modifications After modifications

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top