Swift : Alternative to .classForCoder()

倖福魔咒の 提交于 2020-01-03 09:09:26

问题


Given the following code:

    return TyphoonDefinition.withClass(AppDelegate.classForCoder()) {
        (definition) in

        definition.injectProperty("assembly")
    })

. . . it is necessary to use .classForCoder(), as .class() is struck out. This is certainly unintuitive compared to simply .class(). Is there an alternative that provides better readability?


回答1:


To obtain a reference to the class Object, simply use 'ClassName.self'

Example:

return TyphoonDefinition.withClass(AppDelegate.self) {
    (definition) in

    definition.injectProperty("assembly")
})


来源:https://stackoverflow.com/questions/25659958/swift-alternative-to-classforcoder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!