Re: NSMutableArray compare:
Re: NSMutableArray compare:
- Subject: Re: NSMutableArray compare:
- From: Stephane Sudre <email@hidden>
- Date: Tue, 4 Jul 2006 14:56:22 +0200
On 4 juil. 06, at 12:09, Yorh wrote:
Hi to all,
I have an NSTableView and an NSMutableArray to compare in order to
sort the NSTableColumns.
I added this code in the tableView data source:
- (void)tableView:(NSTableView *)tableView
mouseDownInHeaderOfTableColumn:(NSTableColumn *)tableColumn{
if ([[tableColumn identifier] isEqual:@"name"]){
[[[[GAChannelList sharedInstance]
allData]valueForKey:@"channelName"]
sortUsingSelector:@selector(compare:)];
}
else if ([[tableColumn identifier] isEqual:@"users"]){
[[[[GAChannelList sharedInstance] allData]valueForKey:@"users"]
sortUsingSelector:@selector(compare:)];
}
[channelListView reloadData];
}
The shared instance returns a NSMutableArray, but if I click on the
table header xcode returns me this error:
*** -[NSCFArray sortUsingFunction:context:]: mutating method sent to
immutable object
This is strange because as I said before I have this code in the
shared instance:
-(NSMutableArray*)allData
{
return allData;
}
OK, but:
1. It does not prove allData is a NSMutableArray in the end
2. Since you're calling valueForKey:@"users"], what matters is the
mutability of the array returned by valueForKey:.
According to the documentation of NSArray:
valueForKey:
- (id)valueForKey:(NSString *)key
Returns an array containing the results of invoking valueForKey: using
key on each of the receiver's objects. The returned array will contain
NSNull elements for each object that returns nil.
It does not state that the array is mutable...
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden