ray john
ray john

Reputation: 261

Realm: Cannot invoke 'objects' with an argument list of type '(Object.Type)'

So I have a very simple Book model in Realm

class Book: Object {

    dynamic var title: String!
    dynamic var author: String!
}

And I'm trying to retrieve all of my books in a helper class:

var userBookLibrary = [Book]()
let realm = try! Realm()    

func getBooksFromLocalDatastore() {
    userBookLibrary = realm.objects(Book)
}

This line:

userBookLibrary = realm.objects(Book)

throws the error in the title.

Have I gone mad or is this not exactly what the Realm documentation tells us to do ?

Upvotes: 7

Views: 1737

Answers (1)

joern
joern

Reputation: 27620

realm.objects() does not return [Book] but Results<Book>?. So you have to change the type of userBookLibrary:

var userBookLibrary = Results<Book>?

Upvotes: 11

Related Questions