ios - Objective C ternary operator vs if statements nil check -


im checking see if array nil , if want set counter variable 0 , length of array if array not nil.

nsuinteger count = 0; if (self.somearray == nil) {     count = 0; } else {     count = self.somearray.count; } 

and works fine expected. when try this:

nsuinteger count = (self.somearray == nil) ? 0 : self.somearray.count 

i [nsnull count] unrecognized selector error. however, when this

([self.somearray iskindofclass:[nsnull class]]) ? 0 : self.somearray.count`  

it seems latter should work me there simple overlooking? nsnull objects nil right? why simple nil check working in if statement , not in ternary operator?

self.somearray nsnull object, not nsarray object.

i suspect got object json message , haven't checked type before storing in class.

once have sorted; works if array set or not:

nsuinteger count = self.somearray.count; 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -