Reputation: 1
I'm trying to build a Pinterest iOS clone as an exercise -- first day using xcode and swift. I can't get any function that uses the Pinterest SDK to work properly. Every function gives a Type Error.
For example, here's the code I'm using for login:
@IBAction func login(_ sender: UIButton) {
PDKClient.sharedInstance().authenticate(
withPermissions: [PDKClientReadPublicPermissions],
from: self,
withSuccess: { (success: PDKClientSuccess!) in
print(success)
},
andFailure: { (failure: PDKClientFailure!) in
print(failure)
}
)
}
I get back the following error:
Cannot convert value of type '(PDKClientSuccess!) -> ()' to expected argument type 'PDKClientSuccess!'
If I do withSuccess: PDKClientSuccess! then I get the following error:
ViewController.swift:28:26: Cannot convert value of type 'PDKClientSuccess!.Type' (aka'ImplicitlyUnwrappedOptional<(Optional<PDKResponseObject>) -> ()>.Type') to expected argument type 'PDKClientSuccess!'
If I just do withSuccess: { (PDKClientSuccess) in print("success") } xcode doesn't complain, but it also doesn't work properly.
The documentation seems to be a bit outdated, but here's how they expect the function to look:
- (void)authenticateWithPermissions:(NSArray *)permissions
fromViewController:(UIViewController *)presentingViewController
withSuccess:(PDKClientSuccess)successBlock
andFailure:(PDKClientFailure)failureBlock;
Though based on the error messages I'm getting from xcode, the function is now called 'authenticate', 'withPermissions' is a parameter, and 'fromViewController' is now just 'from'.
Upvotes: 0
Views: 149
Reputation: 1
So the issue was I was passing a function when it's expecting a closure. So the TypeError makes sense.
The correct code is:
PDKClient.sharedInstance().authenticate(
withPermissions: [PDKClientReadPublicPermissions],
from: self,
withSuccess: { (success) in print(success ?? "succeeds") },
andFailure: { (failure) in print(failure ?? "fails") }
)
Unfortunately this hasn't solved everything... I never hit the withSuccess or withFailure, but at least xcode doesn't complain.
Upvotes: 0