nspredicate

CoreData predicate ANY + AND with to-many relationship

。_饼干妹妹 提交于 2020-01-06 04:07:10
问题 I have those entities defined in my model: [Sample] - results (to many relation with [Result]) [Parameter] - results (to many relation with [Result]) - compliant (number value) [Result] - parameter (relation with [Parameter]) - sample (relation with [Sample]) For a [Sample] object "MySample", I need to get all [Parameter] objects that have: [Result].compliant = 1 AND [Result].sample = MySample So, I'm trying to fetch [Parameter] objects using predicate that will be a sum of those predicates:

Managed Objects have different id when fetched

别说谁变了你拦得住时间么 提交于 2020-01-04 13:48:19
问题 im working with coredata and there is a concept that im not getting; i've 2 managed objects ACConversation and ACMessages with a one to many relationship, so i'm saving a message associated to a conversation and trying to fetch them back based on: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.conversation = %@", self.conversation]; but the id associated to the object is different (it seems more a memory address) and with the above predicate it doesnt fetch anything: 2013-01

Managed Objects have different id when fetched

雨燕双飞 提交于 2020-01-04 13:47:42
问题 im working with coredata and there is a concept that im not getting; i've 2 managed objects ACConversation and ACMessages with a one to many relationship, so i'm saving a message associated to a conversation and trying to fetch them back based on: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.conversation = %@", self.conversation]; but the id associated to the object is different (it seems more a memory address) and with the above predicate it doesnt fetch anything: 2013-01

Core data. NSPredicate issue using constant literals as names of properties

 ̄綄美尐妖づ 提交于 2020-01-04 12:45:00
问题 I have NSManagedObject with properties. Suppose that one property it is: @property (retain, nonatomic) NSString *city; For fetching data form core data I always use NSPredicate . The predicate looks like below: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K == %@", @"city", @"San Francisco"]; But the problem here that the project use key "city" as undefined key in meaning like a constant. So lets suppose that I use key "city" in my app 1000 times, so then I need to replace all

how to build a NSPredicate filtering all days in a month using NSDate?

随声附和 提交于 2020-01-04 02:02:15
问题 Is there a way to get all days in a month generically ? Something like this: [NSPredicate predicatewithFormat@"(date.firstDayOfMonth >= @)AND(date.lastDayOfMonth <= @)"]; 回答1: Yes. You need to figure out what the first instant of the month is, as well as the first instant of the next month. Here's how I would do it: NSDate *now = [NSDate date]; NSCalendar *calendar = [NSCalendar currentCalendar]; NSDateComponents *nowComponents = [calendar components:NSEraCalendarUnit | NSYearCalendarUnit |

Core Data NSPredicate filter by entity class?

梦想与她 提交于 2020-01-03 09:12:11
问题 How would I create an NSPredicate to filter by entity of class Contact ? The solution to NSPredicate check for kind of object class crashes: [NSPredicate predicateWithFormat:@"person.class == %@", [Contact class]]; *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath person.class not found in entity <NSSQLEntity User id=12>' Background I have the Core Data entities User (app user) & Contact (address book contact), both children of Person (abstract

Filtering a large NSArray with NSPredicate

允我心安 提交于 2020-01-03 06:40:10
问题 I have an array containing 170k strings (words in a dictionary), and a string, looking something like "glapplega". I'm trying to extract the word "apple" from the string (with "apple" being a word in the array). I also need to make sure that the extracted word is at least 3 characters. The code I have right now is the following: NSPredicate *wordPredicate = [NSPredicate predicateWithFormat:@"'%@' contains[cd] SELF", string]; NSPredicate *lengthPredicate = [NSPredicate predicateWithFormat:@

Core data - Building a NSPredicate from a ManyToMany relationship

大憨熊 提交于 2020-01-03 04:50:14
问题 This is a follow up question to my previous question on: Core data: Managing employee contracts in a many-to-many relationship? There is a diagram on that question, and as a quick reminder there is the following: company --< contracts >-- employees I have been able to manually save 1 entity inside each of the entities, and verified them all in NSLog. I've created a CompanyListPage which lists all companies. The idea is that when you click on a company you will be presented with a list of all

Determining if an NSDate is today in NSPredicate

大城市里の小女人 提交于 2020-01-02 07:12:13
问题 I've tried multiple methods and tried some suggestions on this site, but how can I determine if a CoreData attribute "dueDate" is equal to "Today", I know NSDate is a specific time as well but I want the predicate to return if it is the same day/month/year regardless of what the time is in the day. Any suggestions? 回答1: This is what I came up with: - (NSPredicate *)matchAttribute:(NSString *)attributeName withDate:(NSDate *)date { NSDateComponents *components = [[NSCalendar currentCalendar]

What is the bindings parameter for the block in predicateWithBlock: used for?

二次信任 提交于 2020-01-01 07:32:22
问题 The declaration for +[NSPredicate predicateWithBlock:] looks like this: + (NSPredicate *)predicateWithBlock:(BOOL (^)(id evaluatedObject, NSDictionary *bindings))block Apple's documentation for the second parameter to the block, bindings , says that it is: The substitution variables dictionary. The dictionary must contain key-value pairs for all variables in the receiver. I can't figure out why this parameter is needed -- nor have I seen it being used anywhere. Why is it there? Also, do I