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 6859009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:13:50+00:00 2026-05-27T02:13:50+00:00

This is my first time trying to use both ARC and Core Data. I

  • 0

This is my first time trying to use both ARC and Core Data. I can’t seem to figure out why my code is crashing.

in the .h I have:

@interface Foo : NSObject {
}
@property (nonatomic,strong) NSString *name;
@property (nonatomic,strong) NSString *email;
@property (nonatomic) BOOL myBool;
@property (nonatomic) float myFloat;

in the .m

@implementation User

@dynamic name;
@dynamic email;
@dynamic myBool;
@dynamic myFloat;

User *user = (User *)[NSEntityDescription insertNewObjectForEntityForName:@"User" inManagedObjectContext:[appDelegate managedObjectContext]];

[user setName:[[[dictionary objectForKey:@"user"] objectForKey:@"user"]objectForKey:@"name"]];
[user setEmail:[[[dictionary objectForKey:@"user"] objectForKey:@"user"]objectForKey:@"email"]];
[user setAuthorisation_token:[[[dictionary objectForKey:@"user"] objectForKey:@"user"]objectForKey:@"authentication_token"]];
[user setMyFloat:5]; <------ crash when set to anything other than 0 (eg,setting to FALSE will crash it).
[user setMyBool:FALSE]; <---- crash when set this to anything other than 0.

Basically whenever I try to use a type other than a string I am getting EXEC crash on that particular line. When I use strings for everything it is fine. In my.xcdatamodeld file I have myFloat set to FLOAT and myBool set to BOOLEAN

kill
error while killing target (killing anyway): warning: error on line 2184 of "/SourceCache/gdb/gdb-1708/src/gdb/macosx/macosx-nat-inferior.c" in function "void macosx_kill_inferior_safe()": (os/kern) failure (0x5x)
quit
Program ended with exit code: 0
  • 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-27T02:13:51+00:00Added an answer on May 27, 2026 at 2:13 am

    You can’t use @dynamic for primitives (like float and BOOL) because Core Data won’t create implementations for them.

    So the reason why your code is crashing is because when you use @dynamic you are telling the compiler “I promise that an implementation for these getters and setters will be available at runtime”. But since Core Data doesn’t create them then your code tries to call methods that doesn’t exist.

    Instead there are two things you could do: Use an NSNumber for both the BOOL and the float or implement your own getters and setters.

    Using NSNumber:
    Core Data only uses objects and not primitives but you can specify boolean or float in the Model. When you call [user myFloat] you will actually get an NSNumber back with the float value inside it. To access the primitive you then call float f = [[user myFloat] floatValue];. The same thing goes for the boolean, it also gets stored in an NSNumber. So when you try to access it you will get back an NSNumber that you need to call BOOL b = [[user isMyBool] boolValue]; to get the primitive back.

    The same thing goes the other way around, when setting myFloat and myBool, you need to store them inside an NSNumber, e.g. [user setMyFloat:[NSNumber numberWithFloat:f]]; and [user setMyBool:[NSNumber numberWithBool:b]];.

    To use this approach you would have to change your last two properties to

    @property (nonatomic, strong) NSNumber *myBool;
    @property (nonatomic, strong) NSNubmer *myFloat;
    

    but you can keep the @dynamic for both of them.

    Implementing you own getters and setters:
    For your convenience, you may want your “user” object to get and set the primitive types, float and BOOL, directly. In that case you should keep the properties as float and bool and in your implementation file (.m) remove the @dynamic lines for myFloat and myBool.

    To implement the getter and setter you need to know a little about KVC/KVO and Core Data. In short: you need to tell the system when you are about to access or change a property and when yo u are done accessing or changing it, since Core Data won’t do it for you. Between the “will access/change” and “did access/change” you are free to retrieve or modify the properties. One more caveat is that Core Data still cannot save the BOOL and float directly, so they need to be packaged into and unpackaged from NSNumbers when getting and setting.

    Further, you can’t call [self setValue:ForKey:]; or [self valueForKey:@""]; because that would cause the method you are in to call itself and throw you into an infinite loop. Core Data solves this use-case by allowing you to get and set the value without hitting your own implementation by calling [self setPrimitiveValue:ForKey:] and [self primiveValueForKey:]. Note: primiteValueForKey has nothing to do with primitive types (int, float, BOOL) but is just the name of the methods you use to get and set values in Core Data directly.

    The implementation for your float and BOOL would look something like this:

    - (float)myFloat 
    {
        [self willAccessValueForKey:@"myFloat"];
        float f = [[self primitiveValueForKey:@"myFloat"] floatValue];
        [self didAccessValueForKey:@"myFloat"];
        return f;
    }
    
    - (void)setMyFloat:(float)f 
    {
        [self willChangeValueForKey:@"myFloat"];
        [[self setPrimitiveValue:[NSNumber numberWithFloat:f] forKey:@"myFloat"];
        [self didChangeValueForKey:@"myFloat"];
    }
    
    - (BOOL)isMyBool 
    {
        [self willAccessValueForKey:@"myBool"];
        BOOL b = [[self primitiveValueForKey:@"myBool"] boolValue];
        [self didAccessValueForKey:@"myBool"];
        return b;
    }
    
    - (void)setMyBool:(BOOL)b 
    {
        [self willChangeValueForKey:@"myBool"];
        [[self setPrimitiveValue:[NSNumber numberWithBool:b] forKey:@"myBool"];
        [self didChangeValueForKey:@"myBool"];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first time trying to use document classes in AS3 and im
This is the first time I'm trying random numbers with C (I miss C#).
This is my first time making a hash table. I'm trying to associate strings
Disclaimer: This is my first time writing unit tests...be gentle! :) I am trying
I'm trying join in Rails 3 for the first time, and can't get the
I'm using PayPal sandbox for the payment gateway, this is first time I'm trying
I'm trying to use MVVM for the first time. I have a Windows Phone
This is my first time attempting to call an ASP.NET page method from jQuery.
This is my first time using joomla. I don't know if I'm using the
This is my first time with Web services. I have to develop web services

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.