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

using Bolts with Parse Queries #52

Open
ghost opened this issue Jan 27, 2017 · 0 comments
Open

using Bolts with Parse Queries #52

ghost opened this issue Jan 27, 2017 · 0 comments

Comments

@ghost
Copy link

ghost commented Jan 27, 2017

func findAsync(query:PFQuery<PFObject>) -> BFTask<[PFObject]> {
        let task = BFTaskCompletionSource<[PFObject]>()
        
        query.findObjectsInBackground { (results:[PFObject]?, error:Error?) in
            if (error == nil) {
                task.setResult(results!)
            } else {
                task.setError(error!)
            }
        }
        
        return task.task
    }

unfortunately, the above code throws the error

Type [PFObject] does not conform to protocol for 'AnyObject'

however, I need to type as [PFObject] to put the results of the query as the result to the task.

how do I accomplish this in Swift 3?

i was able to get past the error by using NSArray, however the result for the function never seems to get set, waituntilfinished just hangs.

func findAsync(query:PFQuery<PFObject>) -> BFTask<NSArray> {
        let task = BFTaskCompletionSource<[NSArray]>()
        
        query.findObjectsInBackground { (results:[PFObject]?, error:Error?) in
            if (error == nil) {
                task.setResult(NSArray.init(results!))
                print(task.task.result!) // at this point i can verify that the result appears to be the desired
            } else {
                task.setError(error!)
            }
        }
        
        return task.task
    }

but calling the function with self.findAsync() with a query i know returns data, just simply returns nil or an uncompleted task

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

0 participants