swift - Parse.com for Xcode to make simple app like trivia crack type -
// // viewcontroller.swift // ap attack // // created ddfulton on 5/8/15. // copyright (c) 2015 ddfulton. rights reserved. // import uikit import parse class viewcontroller: uiviewcontroller { var question: string! var answers: [string]! var answer: string! @iboutlet weak var questionlabel: uilabel! @iboutlet weak var button1: uibutton! @iboutlet weak var button2: uibutton! @iboutlet weak var button3: uibutton! @iboutlet weak var button4: uibutton! override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. calldata() } func calldata(){ var query : pfquery = pfquery(classname: "questionsandanswers") query.getobjectinbackgroundwithid("mo4hyeb8ec"){ (objectholder : pfobject!, error : nserror!) -> void in if (error == nil){ self.question = objectholder["question"] string! self.answers = objectholder["answers"] array! self.answer = objectholder["answer"] string! if (self.answers.count > 0){ self.questionlabel.text = self.question self.button1.settitle(self.answers[0], forstate : uicontrolstate.normal) self.button2.settitle(self.answers[1], forstate : uicontrolstate.normal) self.button3.settitle(self.answers[2], forstate : uicontrolstate.normal) self.button4.settitle(self.answers[3], forstate : uicontrolstate.normal) } } else{ nslog("error. wrong!") } } } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } @ibaction func button1action(sender: anyobject) { } @ibaction func button2action(sender: anyobject) { } @ibaction func button3action(sender: anyobject) { } @ibaction func button4action(sender: anyobject) { } }
that's entire code. parse.com organized objectid, createdat, updatedat, acl, questions (string), answers (array of strings), answer (string value number.)
https://www.youtube.com/watch?v=3yeicy7wcba youtube video i'm following directly.
i know i'm missing something, otherwise work, i'm having shitty time debugging it.
i had same problem. spent half day on one. made 2 changes.
check on parse , make sure answer column named "answer". mine named "array", , screwing me up.
i tinkered optionals , exclamation points , question marks. see code below.
(objectholder : pfobject?, error : nserror?) -> void in
if (error == nil){ self.question = objectholder?["question"] as! string self.answers = objectholder?["answers"] as! array self.answer = objectholder?["answer"] as! string
Comments
Post a Comment