خرید بک لینک

Vote count: 0

Using typhoon i inject the property of a Viewcontroller like below:

//in typhoon Assembly class i inject the property of SomeViewController to a singleton instance of foo
public dynamic func fooViewController() -> AnyObject {
    retu TyphoonDefinition.withClass(MyViewController.self) {
        (definition) in

        definition.injectProperty("worker", with: foo())
        definition.scope = TyphoonScope.Singleton
    }
}

//my protocol
@objc
protocol someProtocol {
    optional func hasFinishedWork(value: Bool)
    optional func doSomeWork()
}


//a class that does something
class foo{
    var delegate:someProtocol?
    func doSomething(){
        //how can i set delegate from the viewController?
        delegate?.hasFinishedWork!(true)
    }
}


//my view controller
class MyViewController: UIViewController, someProtocol{

    //typhoon inject this property as a singleton object of type foo()
    var worker:someProtocol?

    //SomeViewController isn't tied to foo since foo gets inject by typhoon
    //i need to set the delegate of foo to that of SomeViewController
    //how can this be done?

    @IBAction func callFoo(sender: AnyObject) {
        worker?.doSomeWork!()
    }

    func hasFinishedWork(value: Bool){
        print(value)
    }
}

I can't figure out how i can set the delegate of foo class to be MyViewcontroller without tying foo and MyViewController directly. Is it possible using typhoon or how i got myslef in a mess?

asked 1 min ago

- - , .

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 9 اسفند 1394 ساعت: 8:32

صفحه بندی