views:

228

answers:

1

I am a bit of a CoreData noob but am slowly getting my head around it. I am having trouble with the following code:

NSArray * artisteIds = [@"1,2,3,4" componentsSeparatedByString:@","];
predicate = [NSPredicate predicateWithFormat:@"(artisteId IN %@)", artisteIds]; 

My Artiste managed object has a NSNumber field of artisteId and I have looped through all Artistes in my object context and there are definately objects with id's 1-420.

But my helper method always returns a empty result set with that query

NSMutableArray* mutableFetchArtistes = [CoreDataHelper searchObjectsInContext:@"Artiste" :predicate :@"title" :YES :managedObjectContext];      

Any suggestions?

To test it works I used the following and got a count of 3 results

predicate = [NSPredicate predicateWithFormat:@"(artisteId = 1) or (artisteId = 2) or (artisteId = 3)", artisteIds];
A: 

I think the array artisteIds should contain NSNumber objects, e.g.

NSArray *artisteIds = [NSArray arrayWithObjects:
    [NSNumber numberWithInteger:1],
    [NSNumber numberWithInteger:2],
    [NSNumber numberWithInteger:3],
    [NSNumber numberWithInteger:4],
    nil];

You could also use NSSet rather than NSArray, but I'm not sure if it makes a difference.

MrMage
OK I understand what you are saying but the harded 1,2,3,4 was just for the example that value is being defined by my data objects so varies each time, is there a way to force it to cast to NSNumber entities?
tigermain
None that I know of. But you could traverse the array and convert every element to an instance of NSNumber. Or use a predicate like `"(artisteId in {1,2,3,4})".
MrMage