Will Larche
Will Larche

Reputation: 3149

NSManagedObject properties set to nil return 0

I know this is probably by design but I thought I'd check with the community first.

How come when I have an NSManagedObject that's new, its NSNumber properties return 0? I want them to be nil til they've been set.

Upvotes: 1

Views: 964

Answers (2)

Matthias Bauch
Matthias Bauch

Reputation: 90117

Did you just forget to uncheck the default value option?
The NSManagedObject will return nil for that attribute if default is unchecked and the attribute was never set. At least that's what happens in my app.

enter image description here

Upvotes: 4

mbh
mbh

Reputation: 3312

It is a NSNumber behavior. Once it is created but not assigned a value, it is set to 0.

Hope that helps

Upvotes: 0

Related Questions