0

In my swift app, I am sending mail to the registered mail ID which is register in parse.com. I searched in docs, Objective c code is having. I couldn't convert it into SWIFT. I am receiving error. My code is below.

//OBJECTIVE C
[PFCloud callFunctionInBackground:@"hello"
                   withParameters:@{}
                            block:^(NSString *result, NSError *error) {
   if (!error) {
     // result is @"Hello world!"
   }
}];

//MY SWIFT CODING

PFCloud.callFunctionInBackground("hello", withParameters: {}, block: {(result: String, error: NSError)} )

//ERROR RECEIVING that conversion not happening.

Kindly guide me.

3
  • Check this : stackoverflow.com/questions/28393453/… Commented Feb 27, 2015 at 11:54
  • .self to reference the type object, If we accept, [block: {(result: String.self, error: NSError.self)}] then another error, "Tuples types (AnyObject!, NSError! and '( )') have different number of elements" Commented Feb 27, 2015 at 12:03
  • PFCloud.callFunctionInBackground("contact_form", withParameters: ["name":"abc", "email":"[email protected]", "message":"xyz"], block: { (result : AnyObject!, error: NSError!) -> Void in }) I am trying in SWIFT. Is this syntax is right??? @ Dharmesh Commented Feb 28, 2015 at 11:36

2 Answers 2

1

You should change your syntax of the withParameter tag. You need to use [:] instead of {}. Also change the type from the result to AnyObject!

I highly recommend you to check this developer guide of parse, where you find all the neccessary informations. Just choose "Swift" as the language to show. You can choose to show Objective-c or Swift sample code in this guide.

PFCloud.callFunctionInBackground("hello", withParameters:[:]) {
  (result: AnyObject!, error: NSError!) -> Void in
  if error == nil {
    // result is "Hello world!"
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

if I run my code, I am getting error in debug area. ""Error Domain=Parse Code=141 "The operation couldn’t be completed. (Parse error 141.)" UserInfo=0x7fc1ca5099b0 {error=function not found, code=141} ""
That means that this function wasn't found in your cloudcode. you should check the quickstart-guide etc. for help
0

for swift 2.0 try this

 PFCloud.callFunctionInBackground("GetUserIntrest", withParameters:nil) {
        (result: AnyObject?, error: NSError?) -> Void in
        if error == nil {
            // result is "Hello world!"
        }
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.