objectsPassingTest:与filteredSetUsingPredicate:?
我想要获取 LinkedAccountFacebook
类型的 AccountUser
的 linkedAccount
,其中 AccountUser
有许多 LinkedAccount< /code>(在核心数据中)。
使用哪个更好?
objectsWithOptions:passingTest:
NSSet *facebookLinkedAccounts = [activeAccountUser.linkedAccountsobjectsWithOptions:NSEnumerationConcurrentpassingTest:^BOOL(id obj, BOOL *stop) { if ([(LinkedAccount *)obj hasType:LinkedAccountTypeFacebook]) { *停止=是; 返回是; } 别的 { 返回否; } }];
filteredSetUsingPredicate:
NSSet *facebookLinkedAccounts = [activeAccountUser.linkedAccountsfilteredSetUsingPredicate: [NSPredicate predicateWithFormat:@"type == %i", LinkedAccountTypeFacebook]];
通过
NSManagedObjectContext
执行获取请求。
或者,有更好的方法吗?
I want to get an AccountUser
's linkedAccount
of type LinkedAccountFacebook
, where AccountUser
has many LinkedAccount
's (in Core Data).
Which is better to use?
objectsWithOptions:passingTest:
NSSet *facebookLinkedAccounts = [activeAccountUser.linkedAccounts objectsWithOptions:NSEnumerationConcurrent passingTest:^BOOL(id obj, BOOL *stop) { if ([(LinkedAccount *)obj hasType:LinkedAccountTypeFacebook]) { *stop = YES; return YES; } else { return NO; } }];
filteredSetUsingPredicate:
NSSet *facebookLinkedAccounts = [activeAccountUser.linkedAccounts filteredSetUsingPredicate: [NSPredicate predicateWithFormat:@"type == %i", LinkedAccountTypeFacebook]];
Perform a fetch request via the
NSManagedObjectContext
.
Or, is there a better way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您已经设置了关系,调用 activeAccountUser.linkedAccounts 将从核心数据中获取所有内容(如果它们是错误的话)。
“linkedAccounts”是一个错误吗?即它已经在内存中了吗?如果是这样,我会使用(2.)。如果数据仍在您的后备存储 ID 中,请执行提取请求,并使用谓词过滤到您需要的链接帐户类型(3.)
或者如果您打算提取所有其他类型,也许最好提取他们都在前面。
并排尝试它们并在它们上运行 Instruments 时间分析器。
Calling activeAccountUser.linkedAccounts will fetch them all from core data (if they are a fault), assuming you have the relationship set up.
Is `linkedAccounts' a fault? i.e Is it already in memory? If so, I'd use (2.). If the data is still in your backing store id execute the fetch request with the predicate filtering to the linked account type you needed so (3.)
Or if you are planning on fetching all the other types anyway, maybe it would be better to fetch them all up front.
Try them both side by side and run the Instruments time profiler on them.