Swift:替代 .classForCoder() [英] Swift : Alternative to .classForCoder()

查看:623
本文介绍了Swift:替代 .classForCoder()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定以下代码:

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

        definition.injectProperty("assembly")
    })

...有必要使用 .classForCoder(),因为 .class() 被删除了.与简单的 .class() 相比,这当然是不直观的.有没有提供更好可读性的替代方案?

. . . 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?

推荐答案

要获得对类 Object 的引用,只需使用 'ClassName.self'

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

示例:

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

    definition.injectProperty("assembly")
})

这篇关于Swift:替代 .classForCoder()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆