I have a weird problem with FetchRequest template.
When i explicitly hardcode the variable I wish to substitute:
NSFetchRequest *fetchRequest = [[[Helper appDelegate] managedObjectModel]
fetchRequestFromTemplateWithName:@"srStoryForLesson"
substitutionVariables:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:2] forKey:@"number"]];
Every thing works fine.
But When I try to set a var as the Integer (as i want it to be dynamic) I get no results from the fetch.
NSInteger number = 2;
NSFetchRequest *fetchRequest = [[[Helper appDelegate] managedObjectModel]
fetchRequestFromTemplateWithName:@"srStoryForLesson"
substitutionVariables:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:number] forKey:@"number"]];
I can not understand what is wrong?
Thanks
Shani
The code you show should work fine. Your error is elsewhere.
I would recommend not using variable names like “number” because their generic nature risk naming collisions in Objective-C’s global name space. A more unique and descriptive name is safer and easier to read months down the road when you revisit the code.