我现在开始获取请求模板,因此将尽力解释。请询问是否需要更多详细信息。
我创建了一个获取请求模板:
并尝试使用以下方法打印所有对象:
- (void)printOfflineActivities
{
EntityManager* entityManager = [[EntityManager alloc] init];
ActivityFetcher *activityFetcher = [[ActivityFetcher alloc] initWithEntityManager:entityManager];
Activity *activity = [activityFetcher activitiesOffline:[NSNumber numberWithBool:YES]];
NSLog(@"printing..%@",activity.name);
}
活动代码离线是
- (Activity*)activitiesOffline:(NSNumber*)offline
{
NSDictionary* variables = [NSDictionary dictionaryWithObject:offline forKey:OfflineTemplatePlaceholder];
NSFetchRequest* request = [entityManager fetchRequestFromTemplateWithName:ActivityOffline substitutionVariables:variables];
Activity* activity = [entityManager entityForFetchRequest:request];
return activity;
}
但这只会打印出最后一个值。我不确定如何打印所有满足条件/表达式的活动?
最佳答案
提取请求模板应如下所示(变量以$表示(例如$ VARIABLE_NAME)):
从模型中检索必要的提取请求,如下所示:
NSFetchRequest* request = [self.managedObjectContext.persistentStoreCoordinator.managedObjectModel fetchRequestFromTemplateWithName:@"ActivityOffline" substitutionVariables:@{@"ANY_VARIABLE_NAME":offline}];
关于ios - 获取请求模板-获取所有对象,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15536024/