Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


value of optional type string not unwrapped did you mean to use or using -'ios,swift'


value of optional type string not unwrapped did you mean to use or  using -'ios,swift'

I have defined a String type computed property:

var name : String {
   //an optional variable
   var theName : String?

  if SOME_CONDITION {
     theName = “I have a name”
 }
 //ERROR: Value of optional type ‘String?’ not unwrapped,  did you mean to use ‘!’ or ‘?’?
 return theName?
}


I want to return whatever theName is, if it is nil, return nil. So I use return theName? , I don’t want to have runtime error, but compiler seems force me to use return theName! , why?
How can I get rid of it & avoid having runtime error if theName is nil
    

asked Sep 7, 2015 by rajesh
0 votes
19 views



Related Hot Questions



Government Jobs Opening


...