Skip navigation
This discussion is archived

Retrieving BOOL from NSManagedObject

4161 Views 6 Replies Latest reply: Oct 8, 2009 3:08 PM by jsalling RSS
Cycles4Fun Level 1 Level 1 (5 points)
Currently Being Moderated
Sep 20, 2009 10:08 PM
I am attempting to retrieve a BOOL from a NSManagedObject. The entity type is boolean and is bound to an NSButton type. The NSButton is able to get and set the BOOL value. The application is able to save and read the BOOL value accurately from the persisted store. However when I attempt to read the value from the NSManagedObject using the valueForKey method I receive an EXCBADACCESS error.

I have done some research and I found this code on a site:

[[NSNumber numberWithInt:((NSInteger)[managedObject valueForKey:@"fieldName"])] boolValue];

This code did not correct the problem. When I checked the class type "NSCFNumber" is returned.

I am not sure how to work with this type. Is there some way to convert this type to a BOOL? Any help will be greatly appreciated.

Thanks in advance.
MacBook Pro 15.4, iMac 20, iPhone 3G, Mac OS X (10.5.8), XCode 3.1
  • Q Lazarus Level 1 Level 1 (80 points)
    Currently Being Moderated
    Sep 22, 2009 10:05 AM (in response to Cycles4Fun)
    It doesn't sound like you actually clicked the link or read any of the NSNumber documentation.
  • jsalling Calculating status...
    Currently Being Moderated
    Oct 8, 2009 3:08 PM (in response to Cycles4Fun)
    You're thinking it's complex, because you're making it complex. How about this?

    BOOL myBool = [[myManagedObject valueForKey:@"myKey"] boolValue];
    Mac Pro


More Like This

  • Retrieving data ...

Bookmarked By (0)


  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.