ios - Will this result in a crash.. ? or can we send a message to nil in Swift as well..? -


i trying head around swift , have doubt.

if let cn = respobj["cabnumber"].string !cn.isempty {    booking.cabnumber = cn } 

i understand check string being nil or not happen in case if response object doesnot have cabnumber key , object pair in it. using swiftyjson.

it must be:

if let cn = respobj["cabnumber"] as? string !cn.isempty {       booking.cabnumber = cn } 

in there, expression let cn = respobj["cabnumber"] as? string check whether key cabnumber exists in dictionary. second expression where ! cn.isempty checks whether value empty string.

note, if cabnumber key exists has json null value, return instance of nsnull instead of nil.


Comments