So I'm looking for a good way to access all the objects of a given type from realm.
extension Object {
static func getAll<T: Object>() -> Results<T>
{
let realm = try! Realm()
let sorts = [SortDescriptor(property: "createdAt")]
let objects = realm.objects(T).sorted(sorts)
return objects
}
}
Example:
class Person: Object {
dynamic var createdAt = NSDate()
}
Then I want to call:
Person.GetAll()
The issue is that this returns "Results< T >". But I want it to return results based on the class type.. So for this case "Results< Person >". I'm assuming the T is just the generic Object.
I feel like I'm really close, just not quite there yet.
Does this make sense?