0

Okay, so I already tried the examples on apple's SDK developer pages and it didn't work. I tried the examples from previous questions on stackoverflow like :

NSEntityDescription  entitydesc = [NSEntityDescription entityForName:@"Model" inManagedObjectContext:context];
NSFetchRequest request = [[NSFetchRequest alloc]init];
[request setEntity:entitydesc];

//tried this style of predicate

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"accessible == %@", [NSNumber numberWithBool:YES]];

//and this one

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"accessible == YES"];
[request setPredicate: predicate];

NSError *error;
NSArray *matchingData = [context executeFetchRequest: request error: &error];

both of which didn't work. In debugger the matchingData shows 0 objects when it should have many.

All my other fetchrequests have worked perfectly fine. This is the only one giving me problems.

The attribute is listed as type Boolean in the .xcdatamodel

The attribute is listed as this under the entity's header file:

@property (nonatomic, retain) NSNumber * accessible;

The data was entered into the core data database as follows:

NSNumber *accessibleFieldValue  = [NSNumber numberWithBool:YES];
[newModel setValue: accessibleFieldValue forKey:@"accessible"];

I've checked and there are no nil values entered in the sqlite database.

What should I do?

3 Answers 3

1

It works fine with the new literals:

 NSPredicate *predicate = [NSPredicate predicateWithFormat:@"done = %@",@NO];
0
NSNumber *accessibleFieldValue  = [NSNumber numberWithBool:YES];
[newModel setValue:accessibleValue forKey:@"accessible"];

accessibleFieldValue or accessibleValue? If you're sure this snippet of code is right, that's where you did wrong.

And b.t.w, you can set value simply like:

newModel.accessible = [NSNumber numberWithBool:YES];
3
  • no. that was just an accident when I posted the code up here. Has nothing to do with that. Dec 5, 2012 at 2:19
  • and no i didn't decide to use dot notation. Dec 5, 2012 at 2:20
  • 1
    Or even shorter newModel.accessible = @YES;
    – Mundi
    Dec 5, 2012 at 15:49
0

I ended up going to the database in sqlite database browser and changing the type for the field value to Numeric. For some reason core data entered the data as an incompatible data type.....don't really know why, but I have a feeling this might be an Xcode bug. As I said, it works now after I changed the field type. I don't think I will be using boolean values in core data any time soon.....at least not until I understand why this was a problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.