【问题标题】:Swift : Alternative to .classForCoder()Swift:替代 .classForCoder()
【发布时间】:2014-09-04 07:47:46
【问题描述】:

给定以下代码:

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

        definition.injectProperty("assembly")
    })

。 . .有必要使用.classForCoder(),因为.class() 被剔除。与简单的.class() 相比,这肯定是不直观的。是否有提供更好可读性的替代方案?

【问题讨论】:

    标签: objective-c swift objective-c-runtime


    【解决方案1】:

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

    例子:

    return TyphoonDefinition.withClass(AppDelegate.self) {
        (definition) in
    
        definition.injectProperty("assembly")
    })
    

    【讨论】:

      猜你喜欢
      • 2014-08-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-07
      相关资源
      最近更新 更多