Re: NSNull vs nil in NSManagedObject setValue: v forKey: k
Re: NSNull vs nil in NSManagedObject setValue: v forKey: k
- Subject: Re: NSNull vs nil in NSManagedObject setValue: v forKey: k
- From: Eagle Offshore <email@hidden>
- Date: Sun, 28 Feb 2010 23:12:59 -0800
Documentation? "NSNull" does not appear in the documentation.
http://developer.apple.com/mac/library/documentation/cocoa/reference/CoreDataFramework/Classes/NSManagedObject_Class/Reference/NSManagedObject.html
NSNull is conceptually the wrapper for nil, like NSNumber is the wrapper for a number.
It is conceptually inconsistent to treat them differently.
NSMutableDictionary* dict = [NSMutableDictionary dictionary];
[dict setObject: 5 forKey: @"foo"] // fails - must have object
[dict setObject [NSNumber numberWithInt: 5] forKey: @"foo"]; // OK
[dict setObject: nil forKey: @"bar"] // fails - must have object
[dict setObject: [NSNull null] forKey: @"bar"]; // OK
NSManagedObject* obj; // gets created somehow
[obj setValue: nil forKey: @"bar"]; // succeeds where NSDictionary fails
[obj setValue: [NSNull null] forKey: @"bar"]; // fails where NSDictionary succeeds
so - this is conceptually buggy thinking and the thoughtful developer could be forgiven for being VERY SURPRISED by this behavior that is NOT DOCUMENTED.
On Feb 28, 2010, at 6:31 PM, Kyle Sluder wrote:
> On Sun, Feb 28, 2010 at 6:16 PM, Eagle Offshore <email@hidden> wrote:
>> Really? This is a problem somehow?
>
> Yes. You can either provide an object or nil. You gave it an object it
> didn't like.
>
>> NSManagedObject couldn't just take the hint and go with nil?
>
> Would you rather an API based on "taking hints" or an API based on
> documentation? You can either provide nil or a string. Why should
> NSManagedObject assume that an object of a certain class should get
> special treatment? Should it do the same for NSValues wrapping an
> integer 0? What about NSNoSelectionMarker or NSNotApplicableMarker?
>
> --Kyle Sluder
_______________________________________________
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