Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ios

swift

realm

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 ?

like image 989
ray john Avatar asked Oct 30 '15 21:10

ray john


1 Answers

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

var userBookLibrary = Results<Book>?
like image 76
joern Avatar answered Sep 21 '22 23:09

joern