executefetchrequest

Fetching child sum from Core Data

ⅰ亾dé卋堺 提交于 2021-02-07 19:55:04
问题 Lets say I have three Entitys. Person: name address (to-many-salary) and (to-many-loans) Salary: income tax Rel: (to-one-Person) Bills amount Rel: (to-one-person) How do I perform a fetch that have a result like this: John Doe, SUM>income, SUM>amount Eva Doe, SUM>income, SUM>amount Using Swift 回答1: This is probably most easily done using Key Value Coding "collection operators" (see here) rather than a fetch. For each person : let name = person.name let totalIncome = person.valueForKeyPath(

Fetching child sum from Core Data

徘徊边缘 提交于 2021-02-07 19:54:16
问题 Lets say I have three Entitys. Person: name address (to-many-salary) and (to-many-loans) Salary: income tax Rel: (to-one-Person) Bills amount Rel: (to-one-person) How do I perform a fetch that have a result like this: John Doe, SUM>income, SUM>amount Eva Doe, SUM>income, SUM>amount Using Swift 回答1: This is probably most easily done using Key Value Coding "collection operators" (see here) rather than a fetch. For each person : let name = person.name let totalIncome = person.valueForKeyPath(

NSPredicate execureFetchRequest not working - possibly due to spaces in string

那年仲夏 提交于 2019-12-25 03:47:11
问题 I am trying to search in CoreData for an object that matches both a recordId and a string name, but it doesn't always find the object. For example, I an searching for an object with id 1000 and name "The Brown Family" (note the 2 spaces between "The" and "Brown"). If I use: NSPredicate *pred = [NSPredicate predicateWithFormat:@"(recordId == %@") AND (name like[cd] %@)", recordId, name]; with recordId=1000 and name="The Brown Family", the fetch request returns nil. If I use: NSPredicate *pred