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?
func findAll<T: Object>() -> [T] {
return getRealm().objects(T.self).map { $0 }
}
func findAll<T: Object>(type: T.Type) -> [T] {
return getRealm().objects(type).map { $0 }
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.