if statement - how to give nil parameter in if condition in swift? -


in objective-c:

if (!myimageview) {     nslog(@"hdhd"); } else {  //do } 

but in swift:

if (!myimageview) {      println("somethin") } else {    println("somethin") } 

this code giving me error:

could not find overload '!' accepts supplied arguments'

myimageview class variable uiimageview.

what should do?

usually, best way deal checking variables nil in swift going if let or if var syntax.

if let imageview = self.imageview {     // self.imageview not nil     // can access through imageview } else {     // self.imageview nil } 

but work (or comparison against nil either == nil or != nil), self.imageview must optional (implicitly unwrapped or otherwise).

non-optionals can not nil, , therefore compiler not let compare them against nil. they'll never nil.

so if if let imageview = self.imageview or self.imageview != nil or self.imageview == nil giving errors, it's because self.imageview not optional.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -