iosswiftparse-platformback4apppfobject

Swift - PFObject return itself from save calback instead of bool


Just wonder if I can save parse PFObject in background and return it in callback instead of Bool.

parseObject.saveInBackground {
                  (success: Bool, error: Error?) in
                  if (success) {
                    completion(.success(true))
                  } else {
                    let error = NSError(domain: "OURTEAM", code: 0, userInfo: [NSLocalizedDescriptionKey: "Save invoice failure"])
                    completion(.failure(error))
                  }
                }

or do I need to re fetch object one more time from remote?


Solution

  • I do not see why you would need the have that object in the callback when you already have the updated instance.

    For example, the parseObject which you are saving is the updated instance once your callback completes, so just reference that.

    You will see that after the save completes that parseObject which you previously had in memory has now been assigned an objected (assuming you created a new object and saved)