Everytime I try to decode the data, the application crashes with:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'PFObject values may not have class: PFRelation'
This is my model:
class ParseUserPosts: PFObject {
@NSManaged var userId: String
@NSManaged var posts: PFRelation<ParsePostModel>
}
class ParsePostModel: PFObject {
@NSManaged var imageURL: String
@NSManaged var userId: String
@NSManaged var caption: String
}
And this is function which decodes:
func decodeUserPostsObject(item: PFObject, onSuccess: @escaping(_ returnedItem: ParseUserPosts) -> Void) {
var userPost = ParseUserPosts(className: "UserPosts")
//MARK: Decode post details
userPost.userId = item["userId"] as! String
userPost.posts = item["posts"] as! PFRelation
onSuccess(userPost)
}
The line that is giving me the issue is:
userPost.posts = item["posts"] as! PFRelation
I've tried:
userPost.posts = item["posts"] as! PFRelation<ParseUserPosts>
However, still no luck. I am using Back4App and in the console the relations are created/updated with no issue at all, however, it's when I try to decode the data into my application the crash occurs.
If anyone could give me an indication as to what I am doing wrong, would be much appreciated.