NSPredicate with CoreData, which can be retrieved with CONTAINS, but cannot be retrieved in any other way.

Asked 2 years ago, Updated 2 years ago, 107 views

I saved CoreData under the entity name Story

.

The contents are only attributes, and
Enter a description of the image here

This is the configuration.

Use NSPredicate CONTAINS to do this

NSFetchRequest* request = [NSFetchRequest fetchRequestWithEntityName:@"Story";
    request.predicate=[NSPredicatepredicateWithFormat:@"tap_countCONTAINS'0'";
    NSArray* result = [[DataBaseManager shared].moc executeFetchRequest:request error:nil];

When I wrote , I got 3 NSManagedObjects with tap_count 0,10,20.

But I only want to take tap_count 0, so

request.predicate=[NSPredicate predictorWithFormat:@"tap_count=='%d',_tapCount];

or something like that

request.predicate=[NSPredicate predictorWithFormat:@"tap_count MATCHES' [%d]'',_tapCount];

I've tried many things, but I can't take them out.

Please tell me how to take it out.Thank you for your cooperation.

objective-c coredata

2022-09-29 22:19

1 Answers

Now you can take it out.

When using the = operator, it is not == but =.

NSFetchRequest* request = [NSFetchRequest fetchRequestWithEntityName:@"Story";
NSSstring*predicateStr = [NSSstring stringWithFormat:@"tap_count='%d',_tapCount];
request.predicate = [NSPredicate withFormat:predicateStr];
NSArray* result=[DataBaseManager shared].moc executeFetchRequest:request error:nil


2022-09-29 22:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.