I am still new to coding. I have setup my signup screen but I wanted to make it mandatory to upload a profile picture during signup. I've tried to add and "if statement" to show an alert if the photo isn't uploaded but I haven't been successful getting it to work. Any suggestions? Here is my code:
class SignUpViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet var usernameField: UITextField!
@IBOutlet var activityIndicator: UIActivityIndicatorView!
@IBOutlet var message: UILabel!
@IBOutlet var emailField: UITextField!
@IBOutlet var passwordField: UITextField!
@IBOutlet var firstNameField: UITextField!
@IBOutlet var lastNameField: UITextField!
@IBOutlet var profilePic: UIImageView!
@IBAction func submitDataAction(sender: AnyObject) {
var userName = usernameField.text
var userEmail = emailField.text
var userPassword = passwordField.text
var firstName = firstNameField.text
var lastName = lastNameField.text
var initialImage = UIImage(named: "DidNotLoad")
var picfile = profilePic.image
let imageData = UIImagePNGRepresentation(picfile)
let imageFile = PFFile(data: imageData)
userEmail = userEmail.lowercaseString
// Start activity indicator
activityIndicator.hidden = false
activityIndicator.startAnimating()
var newUser = PFUser()
newUser.username = userName.lowercaseString
newUser.password = userPassword
newUser.email = userEmail
newUser["FirstName"] = firstName
newUser["LastName"] = lastName
newUser["ProfilePic"] = imageFile
newUser.signUpInBackgroundWithBlock {(succeeded: Bool, error: NSError?) -> Void in
if error == nil {
dispatch_async(dispatch_get_main_queue()) {
self.performSegueWithIdentifier("PushToEventsTableFromSignUp", sender: self)
}
self.activityIndicator.stopAnimating()
}
else {
if let message: AnyObject = error!.userInfo!["error"] {
self.message.text = "\(message)"
}
}
}
}
@IBAction func uploadPhoto(sender: AnyObject) {
//Create variable for image controller
var picPhoto = UIImagePickerController()
picPhoto.delegate = self
picPhoto.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
picPhoto.allowsEditing = true
self.presentViewController(picPhoto, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
self.dismissViewControllerAnimated(true, completion: { () -> Void in
})
profilePic.image = image
}
override func viewDidLoad() {
super.viewDidLoad()
self.makingRoundedImageProfileWithRoundedBorder()
activityIndicator.hidden = true
activityIndicator.hidesWhenStopped = true
// Do any additional setup after loading the view.
}
private func makingRoundedImageProfileWithRoundedBorder() {
self.profilePic.layer.cornerRadius = self.profilePic.bounds.size.width/2;
self.profilePic.layer.masksToBounds = true
// self.profilePic.clipsToBounds = true
//Create Border around profile Pic
self.profilePic.layer.borderWidth = 2.0
self.profilePic.layer.borderColor = UIColor.whiteColor().CGColor
}