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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -