I'm trying to store a dictionary var items : [String:(type:String,item:AnyObject)] = [:]
for example the key is "foo" and items["foo"]?.type = "UILabel"
I want to convert to AnyObject
by a given type from a string.
is it possible to do something like this?:
//This is a string
if let myConvertedItem = items["file"]!.item as? items["file"]!.type{
//myConvertedItem is UILabel here..
}
is there's a better way to do this?
edit: I saw this function _stdlib_getTypeName()
but swift doesn't recognize it. how can I make it declared? will it work also on AnyObject
?
The Solution I'm not looking for:
do something like this:
if items["file"]!.item is UILabel{
//ok it's UILabel
}
if items["file"]!.item is SomeOtherClassName{
//ok it's some other class name
}
because this if list might be very long
thanks!