Swift: Retrieving object values from Parse.com based on another attribute -
so i'm trying retrieve information parse.com database based on attribute other objectid. more specifically, i'd retrieve object without using objectid can read address column. logic far:
write query returns row restaurant name same 'resto'.
(this i'm stuck) retrieve restaurant's address pfquery , assign string value addresslabel.text variable. here code have:
class finalview: uiviewcontroller{ var resto = 'eddies cafe' var address:string! //var phone:string! @iboutlet var restolabel: uilabel! @iboutlet var addresslabel: uilabel! @iboutlet var phonelabel: uilabel! override func viewdidload() { super.viewdidload() //the below query returns 1 row var query = pfquery(classname: "restaurants") query.wherekey("name", equalto: resto) var obj = pfobject.getobjectwithid("i dont want this") address = obj["address"] as? string restolabel.text = resto addresslabel.text = address } }
i've been reading plenty on how it, i'm seeing how retrieve pfobject query it's objectid. know objectid's myself since it's parse.com instance, need app able retrieve data values backend based on restaurant name. there way around this? going wrong? in advance.
try findobjectsinbackgroundwithblock
var query = pfquery(classname:"restaurant") query.wherekey("adress", equalto:"eddies cafe") query.limit = 1 query.findobjectsinbackgroundwithblock { (restaurants: [anyobject]?, error: nserror?) -> void in if error == nil { if let objects = restaurants as? [pfobject] { var firstobject = objects[0] dispatch_async(dispatch_get_main_queue(),{ self.restolabel.text = firstobject["restaurant"] as? string self.adresslabel.text = firstobject["adress"] as? string self.phonelabel.text = firstobject["phone"] as? string }) } } }
i used dispatch_async process view updates in main queue can see result immediately.
Comments
Post a Comment