DryViews In Part1 wasn’t flexible enough to be used widely in a big macOS application I’m working on, so the need for a more flexible and dynamic DryView was pushing.
Introducing, DryView the NSView
A NSView subclass that can be dynamically loading a nib file, set object controller to do whatever binding you need nesting whatever the number of DryViews without a single line of code!
Let’s say you have a core data model object -you can use any Objective-C or Swift NSObject subclasses not just NSManagedObject- named Item and SubItem children of BaseItem super class. To View Item os SubItem you need to show the shared properties intProperty and stringProperty. Using DryView you will no longer need to duplicate views to view each model’s property because you can reuse the BaseItem’s inspector view:
And create a new inspector view for the Item by adding a date field and subItem table only and reuse the BaseItem view for the rest of properties, also the SubItem can be done the same way.
Now combine a view that shows an Item with it’s children inspecting the selected child in the right side of the view to get this:
All what you need to do is to add a custom view, change it’s type to DryView, set the nibName you want to load and reference The NSObjectController to be used in binding if any, and you are ready to GO!!
Without duplicating a single view, compose your own symphony of views and go Dry all the way even in views:
You can find DryView class here and the sample app I made for this post is here
Need an Objective-C or Swift 3 version, stay tuned!