Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-24-2009, 11:19 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 4
Default Odd behavior with NSPredicate and NSMutableArray

Merry Christmas Eve,

In the code below I've got two lines that create the NSPredicate 'searchPredicate' (they're both uncommented here, but in practice I alternate commenting one or the other out to test). When I use the testArray to create the predicate all is great and I get the results I expect, but when I use the self.currentDeckSwitchedOnCategoryArray I get zero results. I have checked many times to ensure both arrays have the same content (see console output below - differing the order of elements does not seem consequential). The only difference between the arrays is that one is an NSArray and the other is an NSMutableArray, although I have tried to convert the latter into an NSArray to see if that was the issue - no joy. Other ideas were the spaces in the strings or even that quotes appear around output in the console (typical when strings contain non-alphanumeric characters). Can anyone spot something that would cause this different behavior or suggest a fix to the problem?
Thanks and hope I can get this straightened out before Xmas day, Joel

>>>>>>>>>

NSArray* testArray = [[NSArray alloc] initWithObjects:@"Upper Body", @"Middle Body", @"Lower Body", @"Full Body", @"Wildcard", nil];
NSLog(@"self.currentDeckSwitchedOnCategoryArray values: %@", self.currentDeckSwitchedOnCategoryArray);
NSLog(@"testArray values: %@", testArray);
NSPredicate *searchPredicate = [NSPredicate predicateWithFormat:@"(ANY Decks.Name == %@) && (Category IN %@)", [deckObject valueForKey:@"Name"], testArray];
NSPredicate *searchPredicate = [NSPredicate predicateWithFormat:@"(ANY Decks.Name == %@) && (Category IN %@)", [deckObject valueForKey:@"Name"], self.currentDeckSwitchedOnCategoryArray];
[fetchRequest setPredicate:searchPredicate];
NSFetchedResultsController* tempFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];
tempFetchedResultsController.delegate = self;
self.fetchedResultsController = tempFetchedResultsController;

>>>>>

2009-12-24 20:44:47.500 FDM_v2.0.25x[819:20b] testArray values: (
"Upper Body",
"Middle Body",
"Lower Body",
"Full Body",
Wildcard
)
2009-12-24 20:44:47.525 FDM_v2.0.25x[819:20b] self.currentDeckSwitchedOnCategoryArray: (
"Full Body",
"Upper Body",
"Middle Body",
"Lower Body",
Wildcard
)
MobileJoel is offline   Reply With Quote
Old 12-24-2009, 11:56 PM   #2 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 4
Default Solved!

Ahhh, nevermind folks. In the process of posting I actually came across the root of the problem (happy trigger finger still submitted the post, evidently). So, just for reference, the code I sent was completely functional, it's just that there was a very subtle timing problem in when the NSMutableArray was getting populated.
MobileJoel is offline   Reply With Quote
Reply

Bookmarks

Tags
nsarray, nsmutablearray, nspredicate

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 253
23 members and 230 guests
ADY, bookesp, chillyh, ckgni, dacapo, Dani77, Davey555, Desert Diva, glenn_sayers, HemiMG, JasonR, LEARN2MAKE, M.A.S., marshusensei, mer10, nobre84, prchn4christ, Raggou, Rudy, ryantcb, themathminister, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,765
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:35 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0