简体   繁体   English

Swift 3 - 如何投射真实结果<Object>到泛型 [T]

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM