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 ?
realm.objects()
does not return [Book]
but Results<Book>?
. So you have to change the type of userBookLibrary
:
var userBookLibrary = Results<Book>?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With