Laurent Sansonetti
lsans****@apple*****
Sat Dec 9 21:43:11 JST 2006
Hi Kimura-san, On Dec 9, 2006, at 11:54 AM, kimura wataru wrote: > Hi, > > RubyCocoa automatically converts Array->NSArray and Hash- > >NSDictionary. > But treatment of nil value is different between Ruby and Cocoa. > > Ruby: > Array, Hash key, Hash value - allows nil > Cocoa: > Array, Hash key - not allows nil > Hash value - allows nil as NSNull > > I wrote a patch to add assertions at conversion and tests. > > * raise ArgumentError for a nil value at Array->NSArray conversion > * raise ArgumentError for a nil key at Hash->NSDictionary conversion > * use NSNull for a nil value of Hash at Hash->NSDictionary conversion > > I think this feature is useful on debugging RubyCocoa applications. > Good catch! However, it looks like NSNull can also be used as NSArray value and NSDictionary key. Why not always using NSNull? >> x = NSMutableArray.alloc.init => #<OSX::NSCFArray:0x24555e class='NSCFArray' id=0x37b420> >> x.addObject(NSNull.alloc.init) => nil >> x.objectAtIndex(0) => #<OSX::NSNull:0x23f9a6 class='NSNull' id=0xa0277020> >> d = NSMutableDictionary.alloc.init => #<OSX::NSCFDictionary:0x2372ec class='NSCFDictionary' id=0x524500> >> d.setValue_forKey('xxx', NSNull.alloc.init) => nil >> d.allKeys.to_a => [#<OSX::NSNull:0x23f9a6 class='NSNull' id=0xa0277020>] Laurent