Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6110729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:32:56+00:00 2026-05-23T14:32:56+00:00

I am using CoreData in an iOS application. Everything works fine except for fields

  • 0

I am using CoreData in an iOS application. Everything works fine except for fields marked as Boolean in xcdatamodel that get modeled and NSNumber.
For this kind of fields I want to write some utility method in extended class, but I was wondering where’s the best location for writing them or what’s the best practice.

In MyManagedObject.h I have:

@interface MyManagedObject : NSManagedObject {
@private
}
@property (nonatomic, retain) NSNumber * mandatory;
@end

Where mandatory is a boolean in data model. This is the generated class from xcode:

@implementation MyManagedObject
@dynamic mandatory;

At this point, for properly using the entity I need to write somewhere some utility wrapper methods, probably in the entity itself, such as:

[myManagedObject mandatoryWrapper:YES];


-(void)mandatoryWrapper:(BOOL)mandatory {
    // convert boolean to number
    self.mandatory=convertedMandatory;
}

But I am aiming to use the original getter/setter for not generating “confusion”:

// setter
myManagedObject.mandatory=YES;
//getter
if(myManagedObject.isMandatory)

but I suppose that rewriting the original methods, will cause some problem later on in the application lifecycle, for example when saving or retrieving in context.

thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:32:57+00:00Added an answer on May 23, 2026 at 2:32 pm

    If you want a true boolean property, then your are forced to change the name. I would recommend just making the it a property of the class and not the entity because the entity doesn’t have to know about them.

    In your case, you would need something like:

    @property BOOL isMandatory;
    
    -(BOOL) isMandatory{
       return [self.mandatory boolValue];
    }
    
    -(void) setIsMandatory:(BOOL) boolVal{
      self.mandatory=[NSNumber numberWithBool:boolVal];
    }
    

    This lets you use convience constructions like:

    If (self.isMandtaory)...
    self.isMandatory=YES;
    

    Core Data is happy because the entity modeled NSNumber property is still there and works as expected but the human can use the easier to comprehend boolean version.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using CoreData in a multi-threaded iOS-app, and everything seems to work fine -
I'm using CoreData (with SQLite as the store) in an iOS 4 iPhone application
I am developing an iOS application that comes pre-loaded with CoreData content. I am
I had memory problems with an universal iOS application: CoreData was using too much
Scenario: Ruby on Rails app that returns JSON to an iOS application using json-framework
I created a CoreData application using the Cocoa Touch Template. I modified the included
I'am currently migrating an iphone application using SQLite to CoreData. I need to do
I am using CoreData in iOS. I have a modal AddViewController, with a RootViewController
I'm using core data in our iOS universal application and want the ability for
We developing a iOS app that uses CoreData. To keep ourselves from going crazy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.