2
\$\begingroup\$

I have a class which will add or edit a child. So whenever I click on "save," I need to check the child image. If it's an image, then I need to upload to the image server. Once that's done only, I need to save all other data to the data server. Here, I am looking for better names for methods save() and updateChild().

 func saveAction() {
      switch validationResult {
      case .Success:
         save()
      case .Failure(let errorType):
         displayErrorAlert(errorType)
      }
 }

func save() {
    let child = addChildView.tableView.datasource
    if let image = child.image {
        uploadImage(image)
    } else {
        self.updateChild()
    }
}

func uploadImage(image: UIImage) {
    UploadManager.uploadImage(image, completion: { (response) in
        switch response {
        case .success:
            self.updateChild()
        case .error:
            self.updateChild()
        }
    })
}

func updateChild() {
    if addChildType == .new {
        addChild()
    } else {
        editChild()
    }
}
\$\endgroup\$
2
  • \$\begingroup\$ if ... { addNewChild() } editChild() or such. \$\endgroup\$ – Joop Eggen Aug 8 '16 at 9:59
  • \$\begingroup\$ Have you considered insert and update to data servers so that it relates to database languages \$\endgroup\$ – Knight0fDragon Aug 18 '16 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.