title: Parse iOS SDK: Understanding Cloud Code
body: <p><strong>Scenario</strong> = I am slowly but surely wrapping my head around what is going on with Parse's cloud code features. I just need some help from those who would like to answer some short, relatively simple questions about what is going on in some sample cloud code functions. </p>
  
  <p>The code I will use in this example is below</p>
  
  <p>1) <strong>cloud code</strong></p>
  
  <pre><code>Parse.Cloud.define('editUser', function(request, response) {
  
      var userId = request.params.userId,
      newColText = request.params.newColText;
  
      var User = Parse.Object.extend('_User'),
      user = new User({ objectId: userId });
  
      user.set('new_col', newColText);
  
      Parse.Cloud.useMasterKey();
      user.save().then(function(user) {
          response.success(user);
      }, function(error) {
          response.error(error)
      });
  
  });
  </code></pre>
  
  <p>2) <strong>called from iOS</strong></p>
  
  <pre><code>[PFCloud callFunction:@"editUser" withParameters:@{
  
      @"userId": @"someuseridhere",
      @"newColText": @"new text!"
  
  }];
  </code></pre>
  
  <p>This code was taken from <a href="https://stackoverflow.com/questions/18649197/parse-com-saving-attributes-on-a-user-fetched-from-a-query-i-e-not-on-the-cu">here</a></p>
  
  <p><strong>Question 1</strong> =  </p>
  
  <pre><code>(request, response) 
  </code></pre>
  
  <p>I am confused by what this is. Is this like typecasting in iOS where I am saying (in the iOS call) I want to pass an NSString into this function ("userId") and inside the cloud code function I'm going to call it "request"? Is that what's going on here?</p>
  
  <p><strong>Question 2</strong> = </p>
  
  <pre><code>Parse.Object.extend('_User') 
  </code></pre>
  
  <p>Is this grabbing the "User" class from the Parse database so that a "PFObject" of sorts can update it by creating a new "user" in the line below it? </p>
  
  <p><strong>Is this like a...</strong></p>
  
  <pre><code>PFObject *userObject = [PFObject objectWithClassName:@"User"]?
  </code></pre>
  
  <p><strong>Question 3</strong> = </p>
  
  <pre><code>user.set('new_col', newColText)
  </code></pre>
  
  <p>This obviously 'sets' the values to be saved to the PFUser (~I think). I know that the "newColText" variable is the text that is to be set - but what is 'new_col'? Only thing I can think of is that this sets the name of a new column in the database of whatever type is being passed through the "request"? </p>
  
  <p><strong>Is this like a...</strong> </p>
  
  <pre><code>[[PFUser currentUser] setObject: forKey:]
  </code></pre>
  
  <p><strong>Question 4</strong> = </p>
  
  <pre><code>Parse.Cloud.useMasterKey() 
  </code></pre>
  
  <p>Without getting too technical, is this basically all I have to type before I can edit a "User" object from another User?</p>
  
  <p><strong>Question 5</strong> = </p>
  
  <pre><code>user.save().then(function(user) {
          response.success(user);
      }
  </code></pre>
  
  <p><strong>Is this like a...</strong> </p>
  
  <pre><code>[user saveInBackgroundWithBlock:]? 
  </code></pre>
  
  <p>and if so, is </p>
  
  <pre><code>function(error) {
          response.error(error)
  </code></pre>
  
  <p>just setting what happens if there is an error in the saveInBackgroundWithBlock?</p>
  
  <p><em>Please keep in mind, I know iOS - <strong>not</strong> JavaScript.</em> So try to be as descriptive as possible to someone who understands the Apple realm. </p>