Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!spool.mu.edu!agate!ziploc!eps From: eps@toaster.SFSU.EDU (Eric P. Scott) Newsgroups: comp.sys.next Subject: How do I sort a list? Summary: It's late, I'm tired, and this is probably a stupid question Keywords: ObjC,AppKit Message-ID: <1645@toaster.SFSU.EDU> Date: 3 Jun 91 09:19:24 GMT Article-I.D.: toaster.1645 Reply-To: eps@cs.SFSU.EDU (Eric P. Scott) Organization: San Francisco State University Lines: 44 Assume I have a list of objects, and I want to sort them according to some arbitrary criteria. As far as I can tell, the least unpleasant approach is to subclass List and use poseAs: to add a sort method: --- SortableList.h | #import | | @interface SortableList:List | { | } | | - sortUsing:(int (*)(const void *, const void *))compar; | | @end --- --- SortableList.m | #import "SortableList.h" | #import | | @implementation SortableList | | - sortUsing:(int (*)(const void *, const void *))compar | { | if (numElements>1) (void)qsort((void *)dataPtr, numElements, | sizeof (id), compar); | return self; | } | | | @end --- (Where do I invoke the poseAs:? appDidInit:?) Now suppose my list of objects is the cellList of a one- dimensional matrix. Does that change things, and if so, how? What if one or more cells are selected before I perform the sort? What if the matrix is an argument to browser:fillMatrix:inColumn:? Am I missing something obvious? (i.e. is there a better way?) -=EPS=-