Search code examples
cocoacore-datacocoa-bindings

Cocoa Bindings - why do I get these characters?


I am trying to learn Cocoa Bindings, and have a simple app with Title, First and Last Name.

Here is a screenshot of the result when I run the app:

enter image description here

I don't understand why I'm getting the null strings in the first and last names.

Everything is built using bindings - there is no code.

The bindings look like this:

enter image description here

Any help would be appreciated... Thanks!

EDIT - here is the attribute values for firstname:

enter image description here

Here is the code for the managed object subclass...

@interface TestEntity : NSManagedObject

@property (nonatomic, retain) NSString * title;
@property (nonatomic, retain) NSString * firstname;
@property (nonatomic, retain) NSString * lastname;

@end


@implementation TestEntity

@dynamic title;
@dynamic firstname;
@dynamic lastname;

- (void) awakeFromInsert
{
    NSLog(@"%s", __FUNCTION__);

    NSString * baseValue = @" ";
    [self setValue: baseValue  forKey: @"firstname"];

} // awakeFromInsert

Solution

  • You bound a control that shows only a single value to "arrangedObjects.yourKey". This provides a collection. If you printed the same thing in the debugger console using po someCollection, you'd see the same format.

    You want "selection.yourKey". Here "selection" means "whatever object is selected in the array controller" and the rest of the keypath is rooted at that object.

    You're probably used to using "arrangedObjects" with a table view, where a column (essentially an array of vertically-stacked fields wants a sorted collection. This is fine for your left-hand table (the "master" view) but your right-hand controls (the "detail" view(s)) depend on its selection.

    I hope this helps.