Search code examples
swiftsalesforceblockobjective-c-swift-bridge

Swift & Salesforce SDK, using SFRestDictionaryResponseBlock


I've been attempting to create a delete request to remove a specific record from my custom objects using SFRestAPI. The code I've written so far is;

let deleteRequest = SFRestAPI.sharedInstance().performDelete(withObjectType: "Event__c", objectId: "Event-00003", fail: { (error :NSError!) -> Void in} as! SFRestFailBlock, complete: SFRestDictionaryResponseBlock)

However, this immediately throws error saying;

Cannot convert value of type 'SFRestDictionaryResponseBlock.Type' (aka '((Optional>) -> ()).Type') to expected argument type 'SFRestDictionaryResponseBlock' (aka '(Optional>) -> ()')

I've been able to get around this issue by casting the Fail block as NSError of type SFRestFailBlock this however doesn't seem to work for Complete Block in swift.

Salesforce SDK Type Definitions for Blocks are

public typealias SFRestFailBlock = (Error?) -> Swift.Void
public typealias SFRestDictionaryResponseBlock = ([AnyHashable : Any]?) -> Swift.Void

Any help will be appreciated, thanks in advance.


Solution

  • Long story short, the guys at SalesForce were able to give me quick solution for this. Turns out I've been using wrong syntax on one of my previous solutions. The working code is:

            SFRestAPI.sharedInstance().performDelete(
            withObjectType: "Event__c",
            objectId: "a000Y00000B3SGbQAN",
            fail: { (error: Error?) in
                self.log(.debug, msg: "Fail " + (error?.localizedDescription)!)
            }) { (response: [AnyHashable : Any]?) in
                self.log(.debug, msg: "Success" )
            };