Cloud Code with Obj-C

In this guide you’ll learn how to use Cloud Code with your Obj-C app.

Step 1 – Create Cloud Code file

Create a new file and name it as ‘main.js’. Add the following code to the file:

Parse.Cloud.define("test", function(request, response) {
    var text = "hello world";
    var jsonObject = {
        "answer": text

The first parameter of the Cloud Code is the function name. It is important to use the very same name you define inside the Cloud Code file into your Android App. You can also pass parameters to your function in your Android App. You can get these parameters by accessing them within the ‘request.params’ object.

Step 2 – Upload your code to Cloud Code

Go to your Dashboard, find the following option and click on it:

Screen Shot 2016-08-09 at 10.41.05 PM

Next, click on “Choose file”, select the .js file, then click on “Save”:


After that, your file will be uploaded. Then, it is necessary to add some code to your App.

Step 3 – Add Objective-C Code:

To call the function, we have to create the parameters that will be passed to the function, pass in the name of the function, pass the parameters and then a function callback. The following code calls the function

// This function calls the Cloud Code
// params has to be defined already
[PFCloud callFunctionInBackground:@"test"
        block:^(NSString *myAlertMsg, NSError *error){
            if(!error) {
                // Everything went alright
            else {
                // Something went wrong

The first parameter of callFunctionInBackground is the function name on the Cloud Code and the second one is the dictionary that has every parameter that will be used by the function. The third argument is the block that will be executed after the function has been called.

Here’s the git repository for the guide: