ios - What is the existence operator in Swift? -
in objective c valid line of code
self.scrollview.contentsize = self.image ? self.image.size : cgsizezero; which checking if self.image nil or not, , choosing left or right value. in swift want recreate same line of code. should same except without semicolon
self.scrollview.contentsize = self.image ? self.image.size : cgsizezero but not valid in swift code getting error, 'uiimage not conform protocol logicvalue'
what right swift code?
this code works if self.image optional. there no reason have otherwise because self.image literally cannot nil.
the next code valid:
var image : uiimage? self.scrollview.contentsize = image ? image!.size : cgsizezero note: must utilize "!" "unwrap" optional variable image can access size. safe because tested before hand not nil.
this work if image implicitly unwrapped optional:
var image : uiimage! self.scrollview.contentsize = image ? image.size : cgsizezero ios swift xcode6
No comments:
Post a Comment