gpt4 book ai didi

iphone - 核心数据:对多关系的谓词

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

我有一个包含 4 个实体的 CoreData 模型。

模型截图 -> http://img96.imageshack.us/img96/7857/screenshot20100209at182.png

状态

-StateName

位置:

-locationName (attribute)

-locationDescription

-locationActivities (relatinship)

-state (relationship)

位置事件:

-location (relationship)

-activity (relationship)

事件

-activityName(attribute)

-locationsActivities (relationship)

我如何编写一个查询来选择所有具有

的位置

(activity = 'Golf' OR activity = 'Swimming') AND state = 'LA'

最佳答案

// With some NSManagedObjectContext *moc
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
[request setEntity:[NSEntityDescription entityForName:@"Location"
inManagedObjectContext:moc]];
[request setPredicate:[NSPredicate predicateWithFormat:
@"(locationActivities.activity.activityName == %@ OR
locationActivities.activity.activityName == %@) AND
state.stateName == %@",
@"Golf", @"Swimming", @"LA"]];
NSError *error;
NSArray *results = [moc executeFetchRequest:request error:&error];

基本上,像往常一样获取核心数据,然后构建适当的谓词来过滤结果(如 Predicate Programming Guide 中所述)。

关于iphone - 核心数据:对多关系的谓词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2232390/

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