-3

I've got in CoreData a @property (nonatomic, retain) NSNumber * hidden; which is Boolean. I am trying using following code [object valueForKey:@"hidden"] How can I compare the returned value, to use it in if() if ([[object valueForKey:@"hidden"] isEqualToString:@"1"]) doesn't work

David
  • 5
  • 4

4 Answers4

2

You can query the bool value of an NSNumber using [[object valueForKey:@"hidden"] boolValue] and that way you can do proper bool handling.

Volker
  • 4,640
  • 1
  • 23
  • 31
1

If it's an NSNumber that you want to treat as a BOOL use...

NSNumber *hidden = [object valueForKey:@"hidden"];
if (hidden.boolValue)
CrimsonChris
  • 4,651
  • 2
  • 19
  • 30
0

If your property 'hidden' is an NSNumber, it's not a string. Try this instead:

if([[object valueForKey: @"hidden"] isEqualToNumber: [NSNumber numberWithBool:true]])

navkast
  • 466
  • 2
  • 13
0
BOOL isOnOrOff = [myEntity.onOrOff boolValue];
RegularExpression
  • 3,531
  • 2
  • 25
  • 36