简体   繁体   中英

How to check if there is a specific user in PFUser's Pointer Array in Parse Subclass?

My class has a PFUser Pointer Array.

I'm trying to check if PFUser.current () in Pointer Array or not.

Here is my snippet code.

class News: PFObject, PFSubclassing {

    @NSManaged var notiBy: PFUser?
    @NSManaged var notiTo: PFUser?
    //[News]()
//    @NSManaged var notiArray: [PFUser]?
    @NSManaged var notiArray: Array<String>


   var newsLiveQuery: PFQuery<News> {
        return News.query()?
            .whereKeyExists("objectId")
            .includeKeys(["notiBy", "postObj", "notiTo", "notiArray"])
            .whereKey("notiArray", equalTo: PFUser.current()!)
            .order(byDescending: "createdAt")
            as! PFQuery<News>
    }

But I got an JSON Error message.

But I can get result of PFObject like this

[<News: 0x1740b5480, objectId: zyCEHc78l6, localId: (null)> {
    checked = 0;
    messageText = Hellow;
    notiArray =     (
        "<PFUser: 0x1742ee800, objectId: a85SoYwEiE, localId: (null)>"
    );
    notiBy = "<PFUser: 0x1742ed100, objectId: tmWHuptLmd, localId: (null)>";
    notiTo = "<PFUser: 0x1742ede00, objectId: a85SoYwEiE, localId: (null)>";
    postObj = "<Post: 0x1742ee700, objectId: CXaSlvrW4G, localId: (null)>";
    type = comment;
}]

Look at that

I think It should be working but...why I can't run query?

Anyone knows about that?

I believe you are not get back the username as a string. Try using PFUser.current()!.username instead

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM