ios - Vote feature implementation -
hello error saying could not find overload != accepts supplied documents
, don't know change. stuck long time. trying implement vote feature in collection view. if user taps button adds 1 vote parse , shows on label. method wrong? below code collection view cell highlighted code error is.
import uikit import parseui import parse var votes = [pfobject]() class newcollectionviewcell: uicollectionviewcell { var parseobject = pfobject(classname: "posts") @iboutlet weak var postsimageview: pfimageview! @iboutlet weak var postslabel: uilabel! @iboutlet weak var voteslabel:uilabel? override func awakefromnib() { super.awakefromnib() // initialization code postslabel.textalignment = nstextalignment.center print("passing11") } @ibaction func vote(sender: anyobject) {
if (parseobject != nil)
{ if let votes = parseobject!.objectforkey("votes") as? int { parseobject!.setobject(votes + 1, forkey: "votes") parseobject!.saveinbackgroundwithtarget(nil, selector: nil) voteslabel?.text = "\(votes + 1) votes" print("passing22") } else { parseobject!.setobject(1, forkey: "votes") parseobject!.saveinbackgroundwithtarget(nil, selector: nil) voteslabel?.text = "1 votes" print("passing33") } }}}
and have error "use of unresolved identifier parse objects"
if (parseobject != nil) { if let votes = parseobject!.objectforkey("votes") as? int { cell.voteslabel?.text = "\(votes) votes" } else { cell.voteslabel?.text = "0 votes" } } return cell}
any appreciated. thank you.
this compiler error appear if parseobject of type pfobject , not pfobject?. can see through code:
var parseobject = pfobject(classname: "posts")
the above line states parseobject of type pfobject , not optional. optional if initializer failable. if parseobject not optional, there no need nil check. hope helps.
Comments
Post a Comment