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

c# SetCompatibleTextRenderingDefault must be called before the first -

C#.NET Oracle.ManagedDataAccess ConfigSchema.xsd -

c++ - Fill runtime data at compile time with templates -