• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Simple Array of Strings Binding Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple Array of Strings Binding Question


  • Subject: Re: Simple Array of Strings Binding Question
  • From: Rob Keniger <email@hidden>
  • Date: Mon, 1 Sep 2008 10:37:58 +1000


On 31/08/2008, at 12:20 PM, Chris Hanson wrote:

More or less expected in hindsight. There's no value of the string to set, instead I want to replace the string object in the array. So... what do I do? Do I really need to make up a model object to contain the string, just to use bindings here? There's absolutely _no_ other data I need to associate with the string, so it'd really be pointless otherwise.

Bindings are intended to work with model objects, so yes, you will need to create a model object "to contain the string."


Think of it this way: The string probably isn't "just a string." It stands for something -- for example, it could be the name of a computer. While the name of a computer might be the only thing worth displaying in that particular table, it doesn't mean that you're not displaying the name *of a* computer.


An NSArray of NSStrings isn't mutable, so if you want to edit the values you need to wrap your NSStrings in some sort of mutable container that is KVC-compliant.

One way is to create an NSMutableArray of NSMutableDictionary objects, each containing an NSString. You can then bind to the dictionary key you've used to store the string and the NSArrayController will be able to update your model object.

E.g:

NSString* myStringKey=@"myStringKey";

NSMutableArray* myStrings=[NSMutableArray arrayWithObjects:
[NSMutableDictionary dictionaryWithObject:@"Foo" forKey:myStringKey],
[NSMutableDictionary dictionaryWithObject:@"Bar" forKey:myStringKey],
[NSMutableDictionary dictionaryWithObject:@"FooBar" forKey:myStringKey],
nil];


You then bind to arrangedObjects.myStringKey in your NSTableView.

Using a vanilla NSMutableDictionary as your "model object" is preferable to creating a custom object just to hold a string.

--
Rob Keniger



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Simple Array of Strings Binding Question (From: Seth Willits <email@hidden>)
 >Re: Simple Array of Strings Binding Question (From: Chris Hanson <email@hidden>)

  • Prev by Date: Re: Seemingly Simple Bindings Question
  • Next by Date: Re: activateIgnoringOtherApps
  • Previous by thread: Re: Simple Array of Strings Binding Question
  • Next by thread: CoreData and mutableArrayValueForKey:
  • Index(es):
    • Date
    • Thread