Create instance of class known at runtime in Swift

后端 未结 3 1212
遇见更好的自我
遇见更好的自我 2021-02-14 14:00

A picture is worth a thousand words, how to rewrite this code from Objective-C to Swift?

- (id) instanceOfClass: (Class) class withInitializer: (SEL) initializer         


        
3条回答
  •  [愿得一人]
    2021-02-14 14:24

    See matt's excellent answer here. Basically with @objc you can mimic the dynamic creation of instances.

提交回复
热议问题