What I want to implement:
class func getSomeObject() -> [SomeObject]? {
let objects = Realm().objects(SomeObject)
return objects.count > 0 ? o
With Swift 4.2 it's as simple as an extension:
extension Results {
func toArray() -> [Element] {
return compactMap {
$0
}
}
}
All the needed generics information is already a part of Results which we extend.
To use this:
let someModelResults: Results = realm.objects(SomeModel.self)
let someModelArray: [SomeModel] = someModelResults.toArray()