Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BFTask's -continueWithExecutor cannot make use of Swift block syntactic sugar #222

Closed
fatuhoku opened this issue Jan 28, 2016 · 4 comments
Closed
Assignees

Comments

@fatuhoku
Copy link

Swift lets you use syntactic sugar when there's a block at the end of a function. When I tried to do this:

task.continueWithExecutor(BFExecutor.mainThreadExecutor()) {
            (task : BFTask) in
}

I surprisingly got:

Ambiguous use of 'continueWithExecutor(_:withBlock:)'

I figured that it was because there were potential matches:

- (BFTask *)continueWithExecutor:(BFExecutor *)executor withBlock:(BFContinuationBlock)block;
- (BFTask *)continueWithExecutor:(BFExecutor *)executor withSuccessBlock:(BFContinuationBlock)block;

This API isn't very optimised for Swift and makes Bolts quite counter-intuitive to learn.

@nlutsenko
Copy link
Member

Hey @fatuhoku, thanks for the report.
Indeed it looks like Swift can't determine which method you meant, since we have two methods that end with a block.

Please keep in mind that this API was designed when public and we didn't know about existence of Swift at all. This said, we are working on making Bolts happen in Swift, which will ultimately solve this.

@nlutsenko nlutsenko self-assigned this Jan 28, 2016
@ghost
Copy link

ghost commented Feb 7, 2016

I've used a swift extension with a diffrent name to avoid this

My code below

extension BFTask {

public func continueExecutionWithExecutor( executor : BFExecutor, continuationBlock : BFContinuationBlock ) -> BFTask {
    return self.continueWithExecutor(executor, withBlock: continuationBlock);
}

}

Hope it helps
Cheers!

@vani2
Copy link

vani2 commented May 13, 2016

You should write w/o training closure
withBlock: { (task) -> AnyObject? in })

@FarisAlbalawi
Copy link

query.findObjectsInBackground().continueWith(executor: BFExecutor.mainThread()) { (task) -> Any? in
                    guard let objects = task.result as? [PFObject] else {
                        return nil
                    }
                    self.inboxArray = objects
                    self.tableView.reloadData()
    
                    return nil
                }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants