• 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: NSMutableArray compare:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >NSMutableArray compare: (From: Yorh <email@hidden>)

  • Prev by Date: First Responder and menus
  • Next by Date: Re: Re: Drag and Drop help
  • Previous by thread: NSMutableArray compare:
  • Next by thread: First Responder and menus
  • Index(es):
    • Date
    • Thread