ios - Use multiple contains functions in if statement (Swift) -
is there way use multiple "contains(array, value)" functions in if statement? have query stores in results in array. if results nil perform set of operations. if, however, array not nil i'd check see if objects appear in it:
var user: pfuser? override func viewdidload() { super.viewdidload() //get 2 players if let user = user{ var userquery = pfquery(classname: "game") userquery.wherekey("user1", equalto: user) userquery.wherekey("isactive", equalto: true) var userquery2 = pfquery(classname: "game") userquery2.wherekey("user2", equalto: user) userquery2.wherekey("isactive", equalto: true) var currentuserquery = pfquery(classname: "game") currentuserquery.wherekey("user1", equalto: pfuser.currentuser()) currentuserquery.wherekey("isactive", equalto: true) var currentuserquery2 = pfquery(classname: "game") currentuserquery2.wherekey("user2", equalto: pfuser.currentuser()) currentuserquery2.wherekey("isactive", equalto: true) var query = pfquery.orquerywithsubqueries([userquery, userquery2, currentuserquery, currentuserquery2]) query.findobjectsinbackgroundwithblock{ (results: [anyobject]!, error: nserror!) -> void in if error == nil{ //if there no active games, start new game if results == nil{ //start game code } else if contains(results, user) [anyobject]! && contains(results, pfuser.currentuser()) [anyobject]! { println(results) } } } } }
using && operator returning error on line: cannot invoke '&&' argument of type '([anyobject]!,[anyobject]!)'
. ideas on how can test see if user , pfuser.current_user() objects found in array?
thanks!
problem trying cast result of contains func call bool in array of anyobjects's.
what need instead compare results of contains(results, user) , contains(results, pfuser.currentuser()) functions calls. wont compile.
in order make compiler happy need cast results array array of [pfuser]
see code:
if let users = results as? [pfuser] { if contains(users, user) && contains(users, pfuser.currentuser()) { println(users) } }
Comments
Post a Comment