September 09, 2005
NSOutlineView, reloading items, and the expansion state
NSOutlineView requires all of the items in it to be pointer unique. If they are not, strange things happen. However, they can be equal (meaning [NSObject isEqual] may return YES).
However, there is a small exception to that rule. If you do a reload, the expansion state of items will be preserved. This expansion state is done by placing the current expanded items into an NSMutableSet. After a reload happens, if an item is in that set it is shown expanded.
What does this mean? Well, to see if an item should be expanded or not, it is looked up in the set. This is done via the item's hashcode and an isEqual comparision. Ahh ha! NSOutlineView is doing some non-pointer unique things here. This means you could potentially switch out items during a reload, and they would still appear expanded after the reload (as long as they have the same hashcode and are isEqual). Another nasty side effect: any items which mutate their hashtable will not appear expanded after a reload! For instance, if you modify an NSDictionary, its hash code will change. Take this point into consideration: the objects you put into an NSOutlineView are NSMutableDictionaries. You do a reload, and after the reload you add a child to one of the items via a key in the NSDictionary. Therefore, the NSMutableDictionary now has a different hashcode, and it will no longer appear expanded! The easy way to work around this is to use a non-mutable object in the outlineview (such as your own object, which might have a dictionary inside of it to keep track of things). Just a neat tip, for those who care or run into this.
Posted by corbin at 03:54 PM | Comments (0)
August 01, 2005
Using Xcode to become a faster programmer
You can utilize some of Xcode's cool features to become a faster Mac OS X programmer. Here are some things which you may not know:
1. Use Code Completion (Code Sense). However, the default keyboard shortcut is lame. Go to the Xcode preferences, Key Bindings:

and change the Code Sense Completion List binding to be Ctrl-Space (I use Option-Space, but really it is the ctrl-key, because I like to swap my ctrl and option keys):

While you are there, set the Code Sense Select Next Placeholder to be Ctrl-/ (that is control forward slash, and again, I have mine set to be option-/ because I swap my keys):
![]()
2. Now that you have it properly setup, use it! Here is how you should be using it:
You want to call a particular method in your current class (self). Type the first few characters:
![]()
Hit Ctrl-Space to bring up the Code Sense window:

Type a few more characters to narrow down what you want, and arrow key down to select the signature you want to use:

Hit enter to add the template into your source code:
![]()
Fill in the first parameter:
![]()
Then, hit Ctrl-/ to go the next completion item and highlight it:
![]()
Repeat with more Ctrl-/ commands until you are done.
3. Congratulations! You are now a faster programmer.
--corbin
Posted by corbin at 10:44 PM | Comments (2)