Reputation: 261
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
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