ios - Unable to remove optional Word from string? -
unable remove optional word
code :
let questionidstr : string! = fetchresults.valueforkey("questionid").objectatindex(counter) as? string
output : optional(16)
required output : 16
you casting optional string as? string
, hence getting optional out. try following:
if let questionidstr = fetchresults.valueforkey("questionid").objectatindex(counter) as? string { // here, questionidstr have non optional value, if nil runtime never here. }
you can force unwrap string without conditional binding follows, please aware unsafe , discourage on above approach:
let questionidstr = fetchresults.valueforkey("questionid").objectatindex(counter) as! string
Comments
Post a Comment