Note that there are some explanatory texts on larger screens.

plurals
  1. POSearching an NSArray of NSDictionaries to verify information
    primarykey
    data
    text
    <p>I have an <code>NSArray</code> full of <code>NSDictionary</code> object. This structure is built from a database. I'm building a verification function that is only included and executed when debugging. The idea is to make sure all the files need are in fact included and any extra files are not included.</p> <p>Based on <a href="https://stackoverflow.com/questions/8340694/search-nsarray-of-nsdictionaries">this</a> question I tried to use a <code>NSPredicate</code> but its flagging every file in thr directory as "File not in Database".</p> <p>What am I doing wrong?</p> <p><code>KEY_DFILE</code> is #defined as <code>@"dFilename"</code>.</p> <pre><code>#ifdef DEBUG - (void)checkItems { NSFileManager *fileManager = [NSFileManager defaultManager]; NSLog(@"-------- Database / File Check --------"); for (NSDictionary* item in self.allItmes) { // ansi items if ([[item objectForKey:KEY_TYPE] isEqualToString:@"ansi"]) { // Make sure the datafile exists NSString* path = [[NSBundle mainBundle] pathForResource:[item objectForKey: KEY_DFILE] ofType:nil inDirectory:@"ansi"]; if (![fileManager fileExistsAtPath:path]) NSLog(@"Can't find file: %@", path); } } NSString *dir = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"ansi"]; NSDirectoryEnumerator* en = [fileManager enumeratorAtPath:dir]; NSString* file; while (file = [en nextObject]) { NSPredicate *p = [NSPredicate predicateWithFormat:@"%@ == %@", KEY_DFILE, file]; NSArray *matchedDicts = [self.allItmes filteredArrayUsingPredicate:p]; if ([matchedDicts count] == 0) { NSLog(@"File not in Database: %@", file); } else if ([matchedDicts count] &gt; 1) { NSLog(@"File in Database more than once: %@", file); } } NSLog(@"---------------------------------------"); } #endif </code></pre>
    singulars
    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