Hi,
I searched for this and apparently this is error is caused when creating the Realm instance in a different queue than where it's used.
But I'm creating and using the Realm instance in the same place. Don't know what's wrong.
This is my load method:
private func load<T: Object>(handler: [T] -> ()) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
var results: [T] = Realm().objects(T).toArray()
dispatch_async(dispatch_get_main_queue(), {
handler(results)
})
})
}
toArray() is implemented like this:
extension Results {
func toArray() -> [T] {
return map(self){$0}
}
}
Confirmed that the error comes from this method, when I comment the GCD code it works. How do I fix it?
Thanks,
Ivan
--
You received this message because you are subscribed to the Google Groups "Realm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to realm-cocoa...@googlegroups.com.
To post to this group, send email to realm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/realm-cocoa/ba7c86b2-116c-45a9-8b25-fe551e57509d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
func load<T: Object, U>(mapper: T -> U, filter filterMaybe: String? = nil, handler: [U] -> ()) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), { var results = Realm().objects(T) if let filter = filterMaybe { results = results.filter(filter) } let objs: [T] = Realm().objects(T).toArray() let models = objs.map{mapper($0)} dispatch_async(dispatch_get_main_queue(), { handler(models) }) })