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
Post a Comment