Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is NSPredicate evaluateWithObject nil when searching for string within NSMutableArray loaded from plist
    primarykey
    data
    text
    <p>I am trying to check within a plist if I had previously saved the value (song) before. Basically why is this:</p> <pre><code> if ([condition evaluateWithObject:favoritesArray] == YES) { return; } </code></pre> <p>being evaluated to nil while this:</p> <pre><code>if ([[favoritesArray filteredArrayUsingPredicate:condition] count] != 0) { return; } </code></pre> <p>works perfectly fine with the exact same condition. </p> <p>Sample of plist:</p> <pre><code>( { artist = Yuna; image = ""; isFavorite = 1; song = "I Wanna Go (BELARBI REMIX)"; thumbnail = "http://userserve-ak.last.fm/serve/64/94177627.png"; } ) </code></pre> <p>printed condition: </p> <pre><code>song = "I Wanna Go (BELARBI REMIX)" </code></pre> <p>Note: changing condition to "song LIKE %@" gives me an "Can't do regex matching on object" error. "song.song" is a NSString.</p> <p>Here is the full code below:</p> <pre><code>- (void) saveFavorite: (Songs*)song { NSMutableArray *favoritesArray = [NSMutableArray arrayWithContentsOfFile:[MBCUtils dataFilePathWithFile:@"favorites.plist"]]; NSPredicate *condition = [NSPredicate predicateWithFormat:@"song == %@" argumentArray:@[song.song]]; if (favoritesArray == nil) { favoritesArray = [NSMutableArray arrayWithCapacity:1]; } else { //favorite is already in list; NSLog(@"filtered favs: %@", [favoritesArray filteredArrayUsingPredicate:condition]); if ([[favoritesArray filteredArrayUsingPredicate:condition] count] != 0) { return; } // why this isn't working is beyond me; if ([condition evaluateWithObject:favoritesArray] == YES) { return; } } [favoritesArray addObject:[song toDictionary]]; [favoritesArray writeToFile:[MBCUtils dataFilePathWithFile:@"favorites.plist"] atomically:YES]; } </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