Like NSFetchedResultsController but for a single managed object. Please see the associated blogpost.
class MyClass {
var frc: SingleFetchedResultController<Profile>?
...
func setup() throws {
let predicate = NSPredicate(format: "username = %@", username)
frc = SingleFetchedResultController(predicate: predicate,
managedObjectContext: moc,
onChange: { (profile, changeType) in
// will be called after the first fetch and after each change to the object
print(profile.username)
})
try frc?.performFetch()
}
}
iOS 8 and above.
Arkadiusz Holko: