【问题标题】:Objection Framework Macros with Swift使用 Swift 的异议框架宏
【发布时间】:2014-08-04 20:29:22
【问题描述】:

我正在尝试让异议框架与 Swift (XCode 6.4) 一起使用。 除了注册/注入对象所需的宏之外,一切都很好,例如objection_register

我遵循“Bridging Cocoalumerjack with Swift”中的方法让宏与 Swift 一起工作,但 XCode 总是抱怨:Use of undeclared identifier 'initialize'ObjectionSwift.m 中实现 objectionRegister 函数时。由于我不熟悉objective-c,所以在查看Objection.h 初始化方法并试图找出问题所在时遇到了困难

感谢您的帮助!

ObjectionSwift.h

#import <Foundation/Foundation.h>
@interface ObjectionSwift : NSObject
+ (void) objectionRegister(NSString *) name;
#endif

ObjectionSwift.m

#import "ObjectionSwift.h"
#import "Objection.h"

@implementation ObjectionSwift
+ (void) objectionRegister:(NSString *) name {
        objection_register_singleton(name)
}
@end

更新 我切换到 Typhoon 作为 DI 框架,它提供了 Swift 支持并且效果很好。

【问题讨论】:

    标签: dependency-injection swift ios8 xcode6


    【解决方案1】:

    你可以使用类变量:

    class ListingsViewController: UIViewController
    {
        class var initialize: Bool
        {
            JSObjection.registerClass(ListingsViewController.self, scope: JSObjectionScopeNormal)
    
            return true
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-09
      • 1970-01-01
      • 2015-05-19
      • 1970-01-01
      • 2010-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多