ios - Define typealias at runtime -


is there way define typealias @ runtime?

in test code have:

typealias classtype = switch { case 0: typealias classtype = b case 1: typealias classtype = c case 2: typealias classtype = d default:typealias classtype = e } 

but classtype still of "type"..

state of art:

class e {} class a: e {} class b: e {} class c: e {} class d: e {}  class service {   func retrieve<t>(completion: (response: responseitems<t>?, error: nserror?) -> void) {} } 

so, in generic part of code:

let service = service()  typealias classtype = switch { case 0: typealias classtype = b case 1: typealias classtype = c case 2: typealias classtype = d default:typealias classtype = e } service.retrieve{ (response: responseitems<classtype>?, error) -> void in  } 

this works called type.

typealias not useable @ runtime. maybe helps, it's realized enum , protocol. try in playground

enum classtype {   case classatype, classbtype, classctype }  protocol responseitem {   var gettype : classtype { } }  class classa: responseitem {    var gettype : classtype { return .classatype } }  class classb: responseitem {   var gettype : classtype { return .classbtype } }  class classc: responseitem {   var gettype : classtype { return .classctype } }  func retrieve( response : ((responseitem?, nserror?) -> void)) {   let atype = classb()   response(atype, nil) }  retrieve{ (response: responseitem?, error) -> void in   if let classtype = response {     switch classtype.gettype {     case .classatype:       println("classa")     case .classbtype:       println("classb")     case .classctype:       println("classc")     }   } } 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -