Jaseem Abbas Jaseem Abbas - 1 month ago 15
iOS Question

Swift 3 - How to cast Real Result<Object> to generic type [T]

I have the following Realm function to fetch all elements from the table in my

Swift 3
app.

//Find all elements in the database
func findAll() -> [T] {
return getRealm().objects(T.self as! Object.Type)
}


How do I cast
Result<Object>
from
Realm
to
[T]
in the return?

Answer
func findAll<T: Object>() -> [T] {
  return getRealm().objects(T.self).map { $0 }
}
Comments