从字符串到协议类型

时间:2017-04-12 21:40:58

标签: swift protocols

我希望做一些有点奇怪的事情。 有没有办法从字符串转到swift中的协议,如

let protocolString: String = "customProtocol"

我有一个类似的协议:

public protocol customProtocol{}

现在稍后,我知道协议的字符串名称,但不知道实际的协议,所以我想做类似的事情:

   if let conformantObject = randomeObject as? protocolFromString(protocolString) {
    //hey it conformed to the protocol    
   }

有没有做过这种转换?

0 个答案:

没有答案