I've used typedef in objective-c to define a completion block like so:
typedef void(^ObjectsOrErrorBlock) (NSArray* objects, NSError* error);
I then have a Swift 3.0 function that takes the ObjectsOrErrorBlock as a parameter. When I try to use the function I receive the error mentioned in the title. This is how I'm attempting to call it:
BPDKAPIClient.shared().getLeadSources({ (leadSourceNames, error) in
self.replaceAll(leadSourceNames.flatMap({$0}))
})
This is how Xcode autofills my function:
BPDKAPIClient.shared().getLeadSources { ([Any]?, Error?) in
code
}
What's wrong with the way I'm calling the function? How should I be calling it?
So it was pointed out that the question is similar to: Calling objective-C typedef block from swift where the solution was an instance method is being called on a non-instance object (aka BPDAPIClient). The shared() function actually returns an instance of instancetype so the getLeadSources method isnt being called on a non-instance object it's being called on some instance. This is how shared is defined:
+ (instancetype) sharedClient;
+ (instancetype)sharedClient {
static BPDKAPIClient *sharedMyManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedMyManager = [[self alloc] init];
// Set the client configuration to be the default.
BPDKAPIClientConfiguration* defaultConfig = [BPDKAPIClientConfiguration defaultConfiguration];
[sharedMyManager setApiClientConfig:defaultConfig];
[sharedMyManager setAppSource:@""];
});
//TODO: add logic to allow first pass at shared manager to be allowed, but subsuquent must check that we called "setAppId:ClientKey:Environment"
return sharedMyManager;
}