Latest 1.0.0
License MIT
Platforms ios 9.0
Frameworks UIKit, CoreData


UIViewController category that detects and reports changes in NSManagedObject’s state and properties and gracefully handles deletions.


  • Integrates into every UIViewController subclass – UITableViewController, UINavigationController, etc.
  • Tracks changes in multiple NSManagedObjects that can be of different Core Data entities, in contradistinction to NSFetchedResultsController.
  • When one of its dependencies – NSManagedObjects – has been deleted:
    • Automatically dismisses itself if it was presented.
    • Pops to previous view controller if it was embedded in UINavigationController‘s stack.
  • Reports about deletions of dependencies and changes to they properties.

Usage scenario

The following UITableViewController subclass represents a customer form. It can be pushed into UINavigationController‘s stack when user selects a row in customers list, or it can be presented as popover.

It will automatically change its title and values of interface elements when represented Core Data object changes, and will dismiss itself when that object removed from context.

@interface BTCustomerVC : UIViewController

- (instancetype)initWithCustomer:(DBCustomer *)customer;

@implementation BTCustomerVC

- (instancetype)initWithCustomer:(DBCustomer *)customer
    self = [super init];

    if (!self) {
        return nil;

    self.modalPresentationStyle = UIModalPresentationPopover;

    // add customer object as dependency
    [self dvc_add:customer];

    return self;

// optional method that will be called when dependency changed
- (void)dvc_updated:(NSManagedObject *)dependency
    if ([dependency isKindOfClass:[DBCustomer class]]) {
        DBCustomer *customer = (id)dependency;
        self.title =;
        self.positionLabel.text = customer.position;



Property Type Description
dvc_defaultAutoDismiss BOOL Class property. Defines default behaviour of newly instantiated controllers. Default value is YES.
dvc_autoDismiss BOOL Will dismiss view controller when the value of this property is YES and any of its dependencies deleted.
dvc_autoDismissAnimated BOOL YES to animate dismissal.
dvc_dependencies NSSet List of view controller’s dependencies.


Method Description
dvc_add: Adds specified NSManagedObject to the list of dependencies and begins to watch for changes in its state and properties.
dvc_remove: Removes specified NSManagedObject from the list of dependencies and no longer tracks its changes.
dvc_removeAll Removes all dependencies.
dvc_contains: Returns YES if specified NSManagedObject is currently listed as receiver’s dependency.

Optional methods

The following methods can be implemented in UIViewController’s subclass.

Method Description
dvc_deleted: This method will be called when specific NSManagedObject that receiver depends on was deleted, its NSManagedObjectContext was reset or its NSPersistentStore was removed from NSPersistentStoreCoordinator.
dvc_updated: Will be called when there were changes in property values of specific NSManagedObject.


  • iOS 9.0+.
  • Accepts NSManagedObjects that belongs to contexts of NSMainQueueConcurrencyType.


BTDependentVC is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "BTDependentVC"

To run the example project, clone the repo, and run pod install from the Example directory first.

Import pod’s header:

#import <BTDependentVC/BTDependentVC.h>


Денис Либит,
[email protected]


BTDependentVC is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "BTDependentVC",
    "version": "1.0.0",
    "summary": "UIViewController category to respond to changes in NSManagedObject's state and properties.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "u0414u0435u043du0438u0441 u041bu0438u0431u0438u0442": "[email protected]"
    "source": {
        "git": "",
        "tag": "1.0.0"
    "platforms": {
        "ios": "9.0"
    "source_files": "BTDependentVC/**/*",
    "frameworks": [

Pin It on Pinterest

Share This