Are there deep reasons to create a collection of funds for storing zero?

Everyone knows that Foundation collections, such as NSArray, NSDictionaryand NSSet, cannot store objects niland you should use them instead NSNull. I’m sure that if I dig into the open source Core Foundation source code, I could even find where it is forced.

I do not understand why they are so designed? Is it simply because it is nilused as a controller in some of its designers, or is there a deeper reason for this behavior?

+4
source share
1 answer

, . , , Cocoa. , , , ", ". , , , nil, , , . - , . .

, :

  • , [dict objectForKey:@"myKey"] nil. , nil @"myKey" , ?
  • ( NSArray , -containsObject: -indexOfObject:) -isEqual: . [nil isEqual:anything] false. nil . nil, ) , -isEqual: , b) .
  • -lastObject, -firstObject -anyObject nil, . a nil, ? , -[NSEnumerator nextObject].
+6

Source: https://habr.com/ru/post/1531973/