casting - convert String to AnyObject in swift -


i have static string variable

struct numb {      static var selectednumber: string = string()  } 

i trying unwrap ( while casting anyobject) value , assign messagecomposeviewcontroller

 if let textmessagerecipients :anyobject  =  numb.selectednumber      {      messagecomposevc.recipients = textmessagerecipients as? [anyobject]     messagecomposevc.body = "testing 123!"     } 

the compiler throwing error

bound value in conditional binding must of optional type 

how convert string anyobject , assign message view controller?

from examples , error see, attempting unwrap value isn't optional. don't need use if let when there value. can force cast using if let this:

if let myvalue:anyobject = numb.selectednumber as? anyobject 

this produce warning saying casting string anyobject succeed, again don't need if let, casts succeed.

your final example should like:

messagecomposevc.recipients = [numb.selectednumber] [anyobject] messagecomposevc.body = "testing 123!" 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -