Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Model Key Path With Multiple Properties

Here, I'm using an NSArrayController to bind properties from Core Data entities into the value of text view table cells.

enter image description here

What syntax do I use to access multiple properties of the entity in the Model Key Path?

Example as a format string: @"%@, %@", lastName, firstName;

like image 921
The Kraken Avatar asked Apr 22 '26 06:04

The Kraken


1 Answers

In the bindings inspector for the text field:

  1. Select "Value With Pattern: Display Pattern Value1"
  2. Bind to the array controller
  3. Controller key = selection
  4. Model key path = lastName
  5. Display pattern = %{value1}@, %{value2}@
  6. Select the now available in bindings inspector: "Display Pattern Value2"
  7. Bind Value2 to AC, selection, firstName

This is documented in the NSTextField section of the Cocoa Bindings Reference.

For completeness, here is some of my own code where I do this sort of binding programmatically:

NSString* bannerPattern = @": %{value1}@ items found, %{value2}@ hidden %{value3}@";
NSString* totalPattern = [dateString stringByAppendingString:bannerPattern];

[ftview.textField bind:@"displayPatternValue1" toObject:ft withKeyPath:@"visibleNumber" options:@{NSDisplayPatternBindingOption : totalPattern}];
[ftview.textField bind:@"displayPatternValue2" toObject:ft withKeyPath:@"hiddenNumber" options:@{NSDisplayPatternBindingOption : totalPattern}];
[ftview.textField bind:@"displayPatternValue3" toObject:ft withKeyPath:@"newString" options:@{NSDisplayPatternBindingOption : totalPattern}];
like image 192
stevesliva Avatar answered Apr 27 '26 08:04

stevesliva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!