• 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: Table Data and NSArrayController
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Table Data and NSArrayController


  • Subject: Re: Table Data and NSArrayController
  • From: email@hidden
  • Date: Wed, 24 Dec 2003 00:28:50 -0500

Thanks for the reply,

I don't think that this is the case, or at least the whole case. I can
still add anything to the NSArrayController. I overrode the add: method
with:

- (void)add: (NSObject*)sender
{
[self addObject: @"Hello"];
}

which successfully adds a Hello to the table and to the preferences. I
think the problem is that the content of the NSStrings (that's the
data) cannot be modified. I decided to then encapsulate the NSStrings,
making them a variable in a class, so that a more proper binding path
could be made with keys in interface builder rather than dealing
directly with objects, but these classes can't be written to file, so I
made a transformer that simply takes an array of strings and converts
it to an array of string encapsulators and vice versa: The code is as
follows:

- (id)transformedValue:(id)value
{
NSLog([value description]);

if ([value isKindOfClass: [NSString class]])
return [Encapsulator encapsulatorWithString: value];
else if ([value isKindOfClass: [NSArray class]])
{
NSMutableArray* array = [NSMutableArray array];
NSEnumerator* valueEnumerator = [value objectEnumerator];

while (NSString* valueString = [valueEnumerator nextObject])
{
[array addObject: [Encapsulator encapsulatorWithString:
valueString]];

return array;
}
}

return nil;
}

However, nothing is done because the value is of type:
_NSControllerObjectProxy

What am I to do? For every great thing that you can do with the
controller layer, there are two extremely annoying inhibitors.

On 23 Dec 2003, at 6:07 PM, Scott Anguish wrote:

> Yep... here's the problem.
>
> You've got a NSMutableArray that you're storing the array of strings
> in. This array is written to the user defaults.
>
> When you read the array from user defaults, you are not getting a
> mutable array, you're getting an immutable array. So, when you try to
> make changes, you get hosed.
>
> You either need to convert that data to a mutable array through a
> value transformer, or write the data out using the value transformer
> NSUnarchivedData. The first would be better in defaults as it would
> be easily editable, but would require you to write the transformer
> (not that it would be a huge effort). The second would require no
> coding, but you're defaults get more obscured in the file (which may
> not be a bad thing)
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Table Data and NSArrayController
      • From: Scott Anguish <email@hidden>
References: 
 >Table Data and NSArrayController (From: email@hidden)
 >Re: Table Data and NSArrayController (From: Scott Anguish <email@hidden>)

  • Prev by Date: CW8 .lib file and Obj-C
  • Next by Date: Re: who is putting up this dialog?
  • Previous by thread: Re: Table Data and NSArrayController
  • Next by thread: Re: Table Data and NSArrayController
  • Index(es):
    • Date
    • Thread