[英]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.我有以下Realm函数来从我的
Swift 3
应用程序中的表中获取所有元素。
//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?如何在返回中将
Result<Object>
从Realm
为[T]
?
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 }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.