> Eric Matecki - Combatants Project on GitHub > > File Combatants.m > > /* > Create and return an array of all the combatants that are not selected > */ > - (NSArray *) arrangeObjects: (NSArray*)iObjectsToArrange > { > printf("Targets::ArrangeObject()\n”);
This smells like C++ which is okay but kind of looks like you need more practice with Objective-C. > unsigned int scCount = (unsigned int)[selectedCombatants count]; > > if( (scCount == 0) || (selectedCombatants == nil) ) > // second test effectively redundant, but... > { > printf(" no objects to arrange\n"); > return [super arrangeObjects: iObjectsToArrange]; > } > > /* > Create and return an array of all the combatants that are not selected > */ Oh dear, why are you doing this? The method arrangeObjects: returns an array containing objects filtered using the receiver's filter predicate and sorted according to the receiver’s sortDescriptors. This includes the selection. By excluding the selection you have changed the semantics of -[NSArrayController arrangeObjects:] for apparently no good reason. > NSMutableArray* arrangedObjects = [NSMutableArray arrayWithCapacity: > [iObjectsToArrange count] - scCount]; > > NSEnumerator* objectEnumerator = [iObjectsToArrange objectEnumerator]; > id item; > while( item = [objectEnumerator nextObject] ) > { > if (![selectedCombatants containsObject: item]) > { > printf(" %s\n", [[item name] UTF8String]); > [arrangedObjects addObject: item]; > } > } > return [super arrangeObjects: arrangedObjects]; > } I agree with Quincey Morris, subclassing NSArrayController is generally a bad idea. It is apparent you need a lot more practice with Objective-C and the Cocoa frameworks before you should ever need to do something like this. A great place to start is with Cocoa Programming for Mac OS X (4th Edition) by Aaron Hillegass if you are doing Objective-C. One of the things Aaron tells you right up front is “Beginning Cocoa programmers are often eager to create subclasses of NSString and NSMutableArray. Don’t. Stylish Objective-C programmers almost never do. Instead, they use NSString and NSMutableArray as parts of larger objects, a technique known as composition.” I hope this helps. --Richard Charles _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com