How can I rewrite in Swift this block?

| | August 7, 2015

I need to rewrite an Objective-C block but I can’t

This is the block in question :

[service executeQuery:query completionHandler:^(GTLServiceTicket *ticket, GTLDriveFileList* files, NSError *error) {
        }];

In Swift, I tried :

service.executeQuery(query, completionHandler: {(ticket:GTLServiceTicket!,files:GTLDriveFileList!,error:NSError!) -> Void in
        })

But the compiler don’t agree with that.

I tried :

service.executeQuery(query, completionHandler: {(ticket:GTLServiceTicket?,files:GTLDriveFileList?,error:NSError?) -> () in
})

But same issue.

And when I cmd+click on the class, I find :

// Clients should create a standard query with any of the class methods in
// GTLQueryDrive.h. The query can the be sent with GTLService's execute methods,
//
//   - (GTLServiceTicket *)executeQuery:(GTLQuery *)query
//                    completionHandler:(void (^)(GTLServiceTicket *ticket,
//                                                id object, NSError *error))handler;

Does anyone knows how to made that ?

Thanks

One Response to “How can I rewrite in Swift this block?”

  1. Try the following in swift.

    service.executeQuery(query) {
    
    ticket, files, error in
    
    //your logic goes here.
    
    }
    

Leave a Reply