cocoa-bindings

What's the point of the "Controller Key" property in IB in the Inspector > Bindings pane?

Apple says: An attribute of an NSController object. When binding to an NSController object, you use this field to select the first entry in the key path. The menu associated with this field displays the properties available on the selected controller object as a convenience. You can type the name of the property or simply select it f...

Storing an NSImage in a Core Data Model

What is the correct way to store an NSImage in a Core Data Model? I have assumed adding an Attribute to an Entity and giving it the Type "Binary" should work, but it is not working. I have a table with a column of NSImageCells and it is not showing anything. ...

Binding a custom NSView: Does it demand creating an IBPlugin ?

I have created a subclass of NSView to draw an image as a pattern: @interface CePatternView : NSView { NSImage* image; id observableObjectForImage; NSString* keyPathForImage; } @end I implemented the following to expose bindings: + (void)initialize { // Expose the "image" binding to IB. [self exposeBinding:@"i...

Setting up KVO for calculated values, based on calculated values.

So I have two objects, Invoice and InvoiceLineItem. InvoiceLineItem has a property called cost and it is dynamically created based on other properties. To help with the KVO/bindings I use: + (NSSet *)keyPathsForValuesAffectingCost { return [NSSet setWithObjects:@"lineItemType", @"serviceCost", @"hourlyRate", @"timeInSeconds", @"prod...

NSTableView and NSOutlineView drag-and-drop

I have an NSTableView and an NSOutlineView, both with their content provided by bindings, that I'd like to have some drag-and-drop functionality: Drag rows from Table A onto a row of Outline B, where they will be copied into a data structure which the row in Outline B represents. Drag a row from Outline B onto another row in Outline B,...

Cocoa binding to a particular item in an array controller

Is it possible using NSArrayController to bind a NSTextField's value to a particular item in the array? In particular, I want to bind to a property on the first item in the array, and show nothing if the array is empty. Using arrangedObjects.command shows just "(" -- presumably it's trying to show a multi-line string with comma-separat...

How to add an object to a programatically bound NSMutableArray?

I have an NSDocument which has the following structure: @interface MyDocument : NSDocument { NSMutableArray *myArray; IBOutlet NSArrayController *myArrayController; IBOutlet MyView *myView; } @end I instantiate the NSArrayController and the MyView in MyDocument.xib, and have made the connections to the File's Owner (MyDoc...

KVO and Bindings problems using my own (not the shared) NSUserDefaults object

I'm subclassing NSUserDefaults in my application. A side effect of this is I can't use [NSUserDefaults sharedUserDefaults], I have to have a class method to provide my own static defaults object. This isn't been a problem in code, but it's proving tricky now that I'm hooking up the preferences UI with bindings. The shared NSUserDefaults...

Is it possible to use Cocoa's Bindings to have an editable NSTableView hooked up to an NSMutableArray?

It seems from the bits and pieces I can scrape together that the answer to this one will be "no", so I'll broadly explain what I'm trying to achieve in (the likely) case that I'm trying to hammer in a screw. What I have in my app is a list of valid file extensions to read in, which I'm recursing through a directory for. I want this to b...

Disable automatic selection of a row after as NSTableView is populated

I have two NSTableViews populated with Core Data that are linked using bindings. When a row is selected in NSTableView1, NSTableView2 is populated and the first row in it is selected. I have registered the NSArrayController that corresponds to NSTableView2 with KVO on its selectionIndex. This is so that when a row is selected in NSTab...

Using predicates on an array controller to filter related objects

I have an application using Core Data and bindings. I want to have an NSSearchField that can search through an NSArrayController bound to an NSTableView. The array controller contains Core Data objects that have a "name" field. I have setup the NSSearchField like this: Bind To: the array controller Controller Key: filterPredicate Pre...

Is it possible to have a binding that combines more than one key path?

Lets say I have an object which has a quantity value. Also, I have an array controller which holds an array of these objects. Furthermore, I have a table which has a percent of total column (i.e. the given row's quantity's percentage of the sum of the quantities for all rows), which needs to be populated with the proper value via bindi...

How do I override NSError presentation when bindings is involved?

One thing I've always had trouble with in Cocoa Bindings has been error presentation, for example when the user types the wrong value into a text field with a formatter attached. Normally I would override willPresentError: somewhere in the responder chain, but my problem is the NSError objects created by the Bindings system doesn't conta...

What's the best way to add a composite property for binding to an existing class

Let's say I have a Size class which has height and width properties (in reality the class is a bit more complex than this, but Size makes a good example). I want to display this as $width x $height in my UI. The obvious way to do this is to bind to a dimensions property which is dependent on width and height. My question is where is t...

How do I bind the enabled binding of a button to whether or not an NSArrayController has a selection?

I want to bind the enabled state of an NSButton to whether or not an NSArrayController has any selected items. How do I do this? ...

Update bound dictionary based on NSTextFieldCell's edited value

I'm working on porting some ancient code (10.2 era) from NSCoding/plist based archiving to using Core Data. I have an NSOutlineView with a custom NSTextFieldCell. The outline view is bound to an NSTreeController to provide the data. The bindings model looks like this: NSTreeController: Managed Object Context -> Controller.managedObjec...

Cocoa bindings: custom setter methods?

I'm using Cocoa bindings to manage a table of objects. I understand how bindings work but I've run into a slight problem. Managing the table of objects would be fine and dandy, except that those objects have to manage actual bluetooth hardware. I'm working off of a framework that provides a class representing a connection to this hardwar...

How to get notified of changes to models via an NSArrayController?

I have an NSView subclass which is bound to the arrangedObjects of an NSArrayController. When the array has an item inserted or removed the view is notified. How do I get it to be notified if a model stored in the array has an attribute changed? Do I need to add my view as an observer to every (relevant) attribute of every item added to...

When should I remove observers? Error about deallocating objects before removing observers.

I am trying to use key-value observing in one of my classes. I register the observers in the init method and remove/deregister them in the dealloc, but I get the following error which seems to occur before my dealloc method gets called, according to my debug prints. An instance 0x583870 of class TekkPoint is being deallocated while key ...

NSTableColumn bound to a BOOL value

i have NSTableView bound to an NSArrayController. in my model i have a BOOL field. i'm trying to bind that value to the column. it displays correctly (1 where value is YES and 0 where value is NO), but it's readonly. =( when i'm trying to edit a value i can't submit it -- when i press enter nothing happens, setter is never invoked. colum...