Parse Swift IOS - PFCloud callFunctionInBackground Selector not invoked

眉间皱痕 提交于 2019-12-11 08:47:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!