Re: Validation error after setting the value of a boolean attribute
Re: Validation error after setting the value of a boolean attribute
- Subject: Re: Validation error after setting the value of a boolean attribute
- From: Lynn Barton <email@hidden>
- Date: Tue, 16 Feb 2010 15:24:29 -0800
On Feb 16, 2010, at 2:38 PM, Steven Degutis wrote:
> Boolean attributes in Core Data are not actually of type BOOL but rather NSNumber. Thus, your NO value is interpreted as nil (since nil == 0 == NO) and you're setting your attribute to nil. If the attribute is required, then nil is not a valid value, and you will get a validation error. Next time, if you look at the header of your file, it tells you what types you should use as arguments to methods, and what types to expect as return values.
Thanks. Silly me, I thought that when the docs said that a BOOL was YES or NO then those were the values to use. I did some research on Key-Value coding and then was able to get the code to work by modifying it to the following:
NSNumber *myBoolNumber = [NSNumber numberWithBool:NO];
[myNewObject setMyBooleanAttribute: myBoolNumber];
>
> Steven Degutis
> Software Engineer
> Big Nerd Ranch, Inc.
> http://www.bignerdranch.com/
>
> On Tue, Feb 16, 2010 at 5:35 PM, Lynn Barton <email@hidden> wrote:
> Why does my Core Data app give me a validation error message, when quitting the app, if the following code is used? I am importing some legacy data to set 5 string attributes of an object, but using this code to set the one BOOL attribute. In my model, myBooleanAttribute has a default value of NO, and the legacy data does not include this attribute, so I can avoid the validation error by omitting the following code, but I would like to know why it causes errors.
>
> [myNewObject setMyBooleanAttribute: NO];
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
>
>
> --
> Steven Degutis
> http://www.thoughtfultree.com/
> http://www.degutis.org/
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden