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

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

Laravel mail error `Swift_TransportException in StreamBuffer.php line 269: Connection could not be established with host smtp.gmail.com [ #0]` -

c# SetCompatibleTextRenderingDefault must be called before the first -