0
votes

when I try to load a related field, I get this error: "*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance"

I feel like it's caused by loading a collection of data that the compiler doesn't know what to do with.

Any help appreciated.

    func findPostsInGroup() {


    let whereClause = "GroupPostBelongsTo.objectId = 'B52F6BEA-79F8-A58B-FF15-AF840BCB2A00'"
    let dataQuery = BackendlessDataQuery()
    dataQuery.whereClause = whereClause
    print("hey")

    var error: Fault?
    let posts = self.backendless.persistenceService.find(Posts.ofClass(),
        dataQuery:dataQuery) as BackendlessCollection
     print("hey")

    if error == nil {
        for post in posts.data as! [Posts] {
            print("post class is \(post.PostText)")
            print("post class is \(post.objectId)")
            print(post.Author.name)


        }

    }

    else {
        print("Server reported an error: \(error)")
    }

}

import Foundation

Groups table class definition

    class Groups : NSObject{

    var groupName: String?
    var UsersInGroup = [BackendlessUser]()
    var ownerId: String?
    var objectId : String?

}

1
Did you check the posts.data value? Does it have something in it?Jelly
Which line is triggering that error? It's obvious you are trying to use NSNull instance (which is the result of a null somewhere) in place of a String or NSString instance. However, it's very difficult to see which line has that problem. It could be post.Author.name, for example.Sulthan
Yes, it's post.Author.name.leecan999
posts.data has data in it.leecan999
Yup, the post.Author.name was empty. Making sure it wasn't by adding a value for it fixed that. Thank you.leecan999

1 Answers

-1
votes

Yup, the post.Author.name was empty. Making sure it wasn't by adding a value for it fixed that. Thank you.