问题
When i call the PFcloud function from normal it return the correct count how ever when i call it with selector, the selector call back function is not fired,
Appreciate if any can can point to me what is the mistake in my code.
Working block - it print out the count successfully
PFCloud.callFunctionInBackground(CloudFunctions.getBookingCount, withParameters: ["camp": "pmAwLDTNc6"], block: {
(result: AnyObject!, error: NSError!) -> Void in
if ( error === nil) {
NSLog("Booking Count call back: \(result) ")
}
else if (error != nil) {
NSLog("error in helloWorld: \(error.userInfo)")
}
})
Not Working block (Selector ) - selector function not called
PFCloud.callFunctionInBackground(CloudFunctions.getBookingCount, withParameters: ["camp": "pmAwLDTNc6"], target: self, selector: "block:")
func block (result: AnyObject!, error: NSError!) {
if ( error === nil) {
NSLog("Booking Count from Block: \(result) ")
}
else if (error != nil) {
NSLog("error in helloWorld: \(error.userInfo)")
}
}
Question:
I need someone to highlight to my the error in writing the selector function as the selector function is not called.
Thanks
回答1:
Your method has two parameters so you need a selector like blockWithResult:error:
回答2:
You're not using the right Swift syntax for selector. Try this instead:
PFCloud.callFunctionInBackground(CloudFunctions.getBookingCount, withParameters: ["camp": "pmAwLDTNc6"], target: self, selector: Selector("block:error:"))
func block(result: AnyObject!, error: NSError!) {
if ( error === nil) {
NSLog("Booking Count from Block: \(result) ")
}
else if (error != nil) {
NSLog("error in helloWorld: \(error.userInfo)")
}
}
来源:https://stackoverflow.com/questions/28393453/parse-swift-ios-pfcloud-callfunctioninbackground-selector-not-invoked