Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
extension RealmStorageContext {
func fetch<T: Storable>(_ model: T.Type, predicate: NSPredicate? = nil, sorted: Sorted? = nil, completion: (([T]) -> ())) {
var objects = self.realm?.objects(model as! Object.Type)
if let predicate = predicate {
objects = objects?.filter(predicate)
if let sorted = sorted {
objects = objects?.sorted(byKeyPath: sorted.key, ascending: sorted.ascending)
completion(objects.flatMap { $0 as? T })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.