Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First thing you are passing <code>error</code> wrong. You need to change that line to</p> <pre><code>[mgr copyItemAtPath:srcPath toPath:dstPath error:&amp;error]; </code></pre> <p>Another thing according to your code after the first run, the above line will fail as there will already be a file that particular name. If you want to initialize only once then I guess you could write something like below which makes more sense:</p> <pre><code>NSError *error = nil; if (![mgr fileExistsAtPath:dstPath]) { [mgr copyItemAtPath:srcPath toPath:dstPath error:&amp;error]; if (error) { NSLog(@"%@",[error localizedDescription]); } } </code></pre> <p>And finally <code>initWithContentsOfFile:</code> might be failing because the plist cannot be parsed into an array. This can be because your plist file's root object is a dictionary (the default when you create the plist using Xcode). </p> <p>Since you are able to parse the plist file in bundle it might be because, you might have accidentally copied the wrong file (or an empty file or a plist with root as dictionary) the first time and then was not able to copy. So try deleting the file from <code>dstPath</code> and try again.</p> <p>To check the file do an <code>NSLog</code> of <code>dstPath</code>. For example if you get something like this in the console:</p> <pre><code>/Users/xxxx/Library/Application Support/iPhone Simulator/5.0/Applications/194351E6-C64E-4CE6-8C82-8F66C8BFFAAF/Documents/YourAppName.app </code></pre> <p>Copy this till the Documents folder, i.e </p> <pre><code>/Users/xxxx/Library/Application Support/iPhone Simulator/5.0/Applications/194351E6-C64E-4CE6-8C82-8F66C8BFFAAF/Documents/ </code></pre> <p>Go to:</p> <blockquote> <p>Finder -> Go -> Go To Folder</p> </blockquote> <p>and paste the path and click on <code>Go</code>. This should take you to the actual directory and check the contents of the plist . Open it as source code in Xcode to see what is the root object.</p> <p>Also try deleting this file you find here and running your app agin.</p> <p>Another way to achieve the above would be to initialize the array from bundle and then write it directly instead of copying the file (but this is not a the direct answer to your problem just a workaround) i.e :</p> <pre><code>NSString *srcPath = [bundle pathForResource:@"MultiSetting" ofType:@"plist"]; NSError *error = nil; //initialize from source NSMutableArray *settingsArray = [[NSMutableArray alloc] initWithContentsOfFile:srcPath]; //write to file NSError *error = nil; //check if file exists if (![mgr fileExistsAtPath:dstPath]) { [settingArray writeToFile:dstPath atomically: YES]; if (error) { NSLog(@"%@",[error localizedDescription]); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload