• 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: Creating NSTableView programmatically
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating NSTableView programmatically


  • Subject: Re: Creating NSTableView programmatically
  • From: Richard Charles <email@hidden>
  • Date: Tue, 19 Dec 2017 18:17:45 -0700

> 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 (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: 
 >Creating NSTableView programmatically (From: Eric Matecki <email@hidden>)
 >Re: Creating NSTableView programmatically (From: Jonathan Mitchell <email@hidden>)
 >Re: Creating NSTableView programmatically (From: Eric Matecki <email@hidden>)
 >Re: Creating NSTableView programmatically (From: Quincey Morris <email@hidden>)
 >Re: Creating NSTableView programmatically (From: Eric Matecki <email@hidden>)
 >Re: Creating NSTableView programmatically (From: Quincey Morris <email@hidden>)
 >Re: Creating NSTableView programmatically (From: Richard Charles <email@hidden>)
 >Re: Creating NSTableView programmatically (From: Eric Matecki <email@hidden>)
 >Re: Creating NSTableView programmatically (From: Quincey Morris <email@hidden>)

  • Prev by Date: Pasteboards and NSSecureCoding
  • Next by Date: Re: Pasteboards and NSSecureCoding
  • Previous by thread: Re: Creating NSTableView programmatically
  • Next by thread: Re: Creating NSTableView programmatically
  • Index(es):
    • Date
    • Thread