2015-11-09 10 views
7

Sto tentando di eseguire una query per tutti gli utenti esistenti nella mia app che l'utente non ha aggiunto come "amico". Sto ottenendo l'errore'Impossibile eseguire una query di confronto per tipo: PFRelation' Swift

Non si può fare una query di confronto per tipo: PFRelation

Qui è il mio codice corrente:

override func queryForTable() -> PFQuery { 

    let currentFriends : PFRelation = PFUser.currentUser()!.relationForKey("friends") 

    // Start the query object 
    let query = PFQuery(className: "_User") 
    query.whereKey("username", notEqualTo: currentFriends) 

    // Add a where clause if there is a search criteria 
    if UserInput.text != "" { 
     query.whereKey("username", containsString: UserInput.text) 
    } 

    // Order the results 
    query.orderByAscending("username") 

    // Return the qwuery object 
    return query 
} 

Come posso risolvere questo problema? Grazie

risposta

5

Ho risolto il mio problema .... in un certo senso. Non sono stato in grado di confrontare la PFRelation, quindi ho creato una classe Parse helper che salva l'utente che aggiunge l'altro utente come "from" e l'utente che aggiungono come "a", quindi sono in grado di confrontarli in questo modo.

let currentUser = PFUser.currentUser()?.username 

    let currentFriends = PFQuery(className: "Friends") 
    currentFriends.whereKey("from", equalTo: currentUser!) 

    // Start the query object 
    let query = PFQuery(className: "_User") 
    query.whereKey("username", doesNotMatchKey: "to", inQuery: currentFriends) 

Spero che questo aiuti qualcuno in futuro.