Advertisement
Guest User

Untitled

a guest
May 1st, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. let okAction = UIAlertAction(title: "Enter", style: UIAlertActionStyle.Default, handler: {(alert :UIAlertAction!) in
  2. let query = PFQuery(className: "Playlists")
  3. query.whereKey("createdbyuser", equalTo: (PFUser.currentUser()?.username!)!)
  4. query.whereKey("playlistName", equalTo: self.inputTextField.text!)
  5. query.findObjectsInBackgroundWithBlock {(objects: [PFObject]?, error: NSError?) -> Void in
  6. if ((error) == nil)
  7. {
  8. dispatch_async(dispatch_get_main_queue(), {
  9. if (objects!.count == 0)
  10. {
  11. let object = PFObject(className: "Playlists")
  12. object["playlistName"] = self.inputTextField.text!
  13. object["createdBy"] = PFUser.currentUser()!
  14. object["track"] = []
  15. object.saveInBackgroundWithBlock({ (success, error) in
  16. if(error == nil)
  17. {
  18. let control = self.storyboard!.instantiateViewControllerWithIdentifier("singlePlaylistVC") as! SinglePlaylistViewController
  19. control.object = object
  20. self.navigationController!.pushViewController(control, animated: true)
  21. }
  22. })
  23. }
  24. else
  25. {
  26. print("You have already created this playlist")
  27. }
  28. })
  29. }
  30. else
  31. {
  32. print(error?.description)
  33. }
  34. }
  35. })
  36. alertController.addAction(okAction)
  37. presentViewController(alertController, animated: true, completion: nil)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement