Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. import Foundation
  2.  
  3. class MyOwnViewController: UIViewController {
  4.  
  5. @IBOutlet var showOption3: UILabel!
  6.  
  7. @IBOutlet var showOption4: UILabel!
  8.  
  9. override func viewDidLoad() {
  10. super.viewDidLoad()
  11.  
  12. var voteCount1 = PFObject(className: "VoteCount")
  13. voteCount1["choices"] = 2
  14. voteCount1["votes"] = Int()
  15. voteCount1["votes2"] = Int()
  16. voteCount1["optionName"] = String()
  17. voteCount1["optionName2"] = String()
  18. voteCount1["objectId"] = String()
  19. voteCount1["pollNumber"] = Int()
  20.  
  21. var query = PFQuery(className: "VoteCount")
  22. query.countObjectsInBackgroundWithBlock {
  23. (count: Int32, error: NSError!) -> Void in
  24. if error == nil {
  25. let randNumber = Int(arc4random_uniform(UInt32(count)))
  26. query.whereKey("pollNumber", equalTo: randNumber)
  27. query.getFirstObjectInBackgroundWithBlock {
  28. (voteCount1: PFObject!, error: NSError!) -> Void in
  29. if error != nil {
  30. NSLog("%@", error)
  31. } else {
  32. let votes = voteCount1["votes"] as Int
  33. let votes2 = voteCount1["votes2"] as Int
  34. let option1 = voteCount1["optionName"] as String
  35. let option2 = voteCount1["optionName2"] as String
  36. self.showOption3.text = "(option1)"
  37. self.showOption4.text = "(option2)"
  38. }
  39. }
  40. } else {
  41. println("error (error)")
  42. }
  43. }
  44. }
  45.  
  46. override func didReceiveMemoryWarning() {
  47. super.didReceiveMemoryWarning()
  48. // Dispose of any resources that can be recreated.
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement