gpt4 book ai didi

ios - 获取请求模板-获取所有对象

转载 作者:行者123 更新时间:2023-11-29 04:03:39 24 4
gpt4 key购买 nike

我正在开始使用获取请求模板,因此将尽力解释。请询问是否需要更多详细信息。

我创建了一个获取请求模板: enter image description here

并尝试在以下方法中打印所有对象:

 - (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;
}

但这仅打印出最后一个值。我不确定如何打印满足条件/表达式的所有事件?

最佳答案

  1. 获取请求模板应如下所示(变量用 $ 表示(例如 $VARIABLE_NAME)): enter image description here

  2. 从模型中检索必要的获取请求,如下所示:

    NSFetchRequest* request = [self.managedObjectContext.persistentStoreCoordinator.managedObjectModel fetchRequestFromTemplateWithName:@"ActivityOffline" substitutionVariables:@{@"ANY_VARIABLE_NAME":offline}];

关于ios - 获取请求模板-获取所有对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15536024/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com