«Невозможно выполнить запрос сравнения для типа: PFRelation» Swift

Я пытаюсь запросить всех существующих пользователей в моем приложении, которых пользователь не добавил в качестве «Друга». я получаю сообщение об ошибке

Не удается выполнить сравнительный запрос для типа: PFRelation

Вот мой текущий код:

 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
}

Как решить эту проблему? Спасибо


person Trip Phillips    schedule 09.11.2015    source источник


Ответы (1)


Я решил свою проблему.... в пути. Мне не удалось сравнить PFRelation, поэтому я создал вспомогательный класс Parse, который сохраняет пользователя, который добавляет другого пользователя, как «откуда», и пользователя, которого они добавляют, как «кому», после чего я могу сравнить их вот так.

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)

Я надеюсь, что это поможет кому-то в будущем.

person Trip Phillips    schedule 13.11.2015