V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
0nlyy0u
V2EX  ›  iOS

搞不懂 objection

  •  
  •   0nlyy0u · 2015-07-24 17:38:30 +08:00 · 1931 次点击
    这是一个创建于 3212 天前的主题,其中的信息可能已经有所发展或是发生改变。

    比如:
    我现在有个Dog类

    @implementation Dog
    
    - (instancetype)initWithName:(NSString *)name {
        if (self = [super init]) {
            _name = name;
        }
        return self;
    }
    

    然后在ViewController里

    @interface ViewController ()
    
    @property (strong, nonatomic) Dog *dog;
    
    @end
    
    @implementation ViewController
    
    objection_requires(@"dog");
    
    objection_initializer(initWithName:, @"Chuck")
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        JSObjectionInjector *injector = [JSObjection createInjector];
        [injector injectDependencies:self];
    
        NSLog(@"%@", self.dog);
        NSLog(@"%@", self.dog.name);
    }
    

    objection_requires(@"dog")是调用的dog的init方法。我现在想调用dog的initWithName。发觉objection_initializer(initWithName:, @"Chuck")根本没起作用呢。

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3062 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 14:57 · PVG 22:57 · LAX 07:57 · JFK 10:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.