gpt4 book ai didi

objective-c - NSManagedObjectIDs 数组,一次获取对象

转载 作者:太空狗 更新时间:2023-10-30 03:43:09 25 4
gpt4 key购买 nike

我有一个 NSManagedObjectID 数组。有没有比遍历数组并单独获取它们更有效的方法来获取关联的托管对象?

最佳答案

使用以下谓词执行fetchRequest

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self in %@", arrayOfIds];

完整示例

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
fetchRequest.entity = myEntityDescription;

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self in %@", arrayOfIds];

fetchRequest.predicate = predicate;
fetchRequest.sortDescriptors = mySortDescriptors;

NSError *error = nil;
NSArray *managedObjects = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
[fetchRequest release]; fetchRequest = nil;

关于objective-c - NSManagedObjectIDs 数组,一次获取对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8204911/

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