snksnk
snksnk

Reputation: 1595

Completion handler for property in swift

I'm trying to use a control called MZFormSheetController in swift. In the example given it provides a property as a completion handler, if I understand correctly, but I'm having difficulties translating it in Swift. Any help would be appreciated.

This is in the obj-c example.

controller.didPresentContentViewControllerHandler = ^(UIViewController *content) {
    NSLog(@"DID PRESENT");
    [self setNeedsStatusBarAppearanceUpdate];
};

I tried many variations and did an extensive search in the web but I could not find anything that could help me so I'm stuck here

controller.didPresentContentViewControllerHandler = (content:UIViewController() -> () {
    println("did present1")
})

Here are the relevant docs: Cocoa Docs:: MZFormSheetPresentationController:: didPresentContentViewControllerHandler

Upvotes: 0

Views: 311

Answers (2)

Greg
Greg

Reputation: 25459

Try add a variable after opening brace

controller.didPresentContentViewControllerHandler = {
    vc in
    println("did present1")
})

Upvotes: 1

Sandeep
Sandeep

Reputation: 21134

If you need to access the view controller then do it like this,

controller.didPresentContentViewControllerHandler = {
    controller in
    println("did present1")
}

Or if you dont need the reference to the view controller, you can simply do,

let controller = Controller()
controller.didPresentContentViewControllerHandler = {
    _ in
     println("did present1")
}

Upvotes: 2

Related Questions