Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed help to quickly search iOS Property List (plist) for value?
    primarykey
    data
    text
    <p>I currently have a plist file in my iOS Project which is downloaded from the web when updates are available and it contains a list of news articles along with images. </p> <p>The application caches the images on the iPhone for offline access, I am currently trying to write a function which will clean the cached files every so often.</p> <p>Currently I have this code which looks in the Temp folder for images and then deletes them, however for each image found I would like it to check if the file name exists as a value in the plist stored as NSDictionary before deleting, however I am not sure of a quick method to search the NSDictionary without the need for a for statement.</p> <p>Any tips would be great.</p> <pre><code> NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:TMP error:nil]; if (files == nil) { // error... NSLog(@"no files found"); } for (NSString *file in files) { NSString *uniquePath = [TMP stringByAppendingPathComponent: file]; if([file rangeOfString: @".png" options: NSCaseInsensitiveSearch].location != NSNotFound) { NSLog(@"%@", file); if ([[NSFileManager defaultManager] removeItemAtPath: uniquePath error: NULL] == YES) NSLog (@"Remove successful"); else NSLog (@"Remove failed"); } } </code></pre> <p>EDIT</p> <p>I have currently added this not sure if its the best way to do it but it works.</p> <pre><code> NSArray *newsArray = [self.newsData allValues]; // Convert the Array into a string NSString *newsString = [newsArray description]; // Perform Range Search. NSRange range; range = [newsString rangeOfString : filename]; if (range.location != NSNotFound) { NSLog(@"The file exists in the plist %@", filename); } else { // Delete the file } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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