I registered for Twitter ages ago, but only recently started actually using it all of the time.
I finally got around to updating Xcode to 3.1 yesterday.
There’s some great stuff in there. At last, the autocomplete of method names puts in tokens for the arguments, so you can just click on the token and then overtype - or just delete it in one go with (forward) delete.
Another cool thing is something that I’ve seen in NetBeans, but the default settings there for it are just annoying. Previous instances of the currently selected variable are highlighted. In Xcode it is a much subtler underline, much better than bright yellow.
This is better than NetBeans in another way - you can click on the item, and access a special contextual menu that allows you to edit every instance of the variable name in your current scope. Thus, refactoring is made much easier.
I’m sure there was something else I really liked too, but I can’t recall what it was.
I have a custom class, called MultiMatrix, which is basically an NSMatrix that has header rows and columns. Selecting a header row or column will select the whole row/column, and selecting the top-left cell will select the whole table. These header cells will also automatically select themselves if their whole row/column/table is selected.
Because I dynamically update the size of the matrix according to some data elsewhere in my program, I needed to embed it into an NSScrollView, so that when the size exceeds the normal size, then users can scroll to select cells.
I did this, and I was having huge slowdowns. I could select cells alright, but selecting a header cell meant about a one second delay.
Solution: turn off the NSScrollView’s copiesOnScroll.
Even though I wasn’t scrolling, for some reason this was causing big performance issues.
I suspect it’s making my custom matrix class do something lots of times, or perhaps it’s related to the controller and the bindings I have set up. Regardless, unchecking the Copies On Scroll box in IB fixed it.
I got tripped up by how C represents Boolean values today.
To save space, but more to make comparisons easy, I was storing a series of bits (representing hours in a day) as integers. I had built up some structure so that my sub-classed NSMatrix could use Cocoa Bindings and be connected to a Controller, so that changing the values in an NSArray of Integers in that controller would change the selected cells in the matrix, and changing the cell selection similarly affects the values stored in the array.
But, and it took me a while to figure this out, I was having problems getting the data back from the array properly. For some reason, numbers greater than 255 were not displaying properly. Basically, I seemed to be losing bits off the top. So I spent ages rewriting the code using longs, long longs, and unsigned long longs, but nothing seemed to work.
Eventually, I pinpointed the error to this: in C an integer with the lower 8 bits all set to 0 evaluates to FALSE.
It doesn’t seem to matter if the integer is a long, or whatever.
Thus, when I checked, using a bitwise AND (& operator), the stored value against a value representing the cell value, and stored it directly in a BOOL, and then used said BOOL to set the selection of that cell, it was evaluating to False for all values greater than 255.
All I needed was to change one line of code:
BOOL highlight = (value & bin);
becomes:
BOOL highlight = (value & bin) > 0;
All fixed.
Mon 14th Jul 2008
XCode 3.1 and “Availability”
Posted late in the morning, filed under Asides , MacOS X , Programming.You can’t have a class with the name “Availability” in a project built with XCode 3.1.
You can with XCode 3.0, but CFNetwork, and I assume a heap of other classes use a class called “Availability” to define if objects are available in a particular version of the OS.
Mon 14th Jul 2008
Public Transit ain’t that great
Posted mid-morning, filed under Rants and Raves , Transport.A couple of weeks ago, there was a puff piece in the local newspaper about a guy and his wife (and teenaged daughter) don’t drive, don’t even have a car. They catch public transport everywhere, and it works for them.
Adelaide is a funny place. It’s not really densely enough populated to have a first-class transit system, and because it isn’t really that good, not many people use it. This is possibly also in part due to how easy it is to drive everywhere in Adelaide, including into the CBD.
I’m a big fan of public transport, it just isn’t working that well here right now.
I’m trying to make a control that allows me to indicate when a record in my application is synced with the AddressBook person of the same name - I have made it so that I can only enable syncing when a person with the exact same name exists in both places, but to indicate it, I want to use a button that shows a pressed-in state, but also alters the image.
I want the image to be black-and-white by default, but when pressed in, it becomes coloured.
Apparently, this isn’t possible. You can either have a button which changes it’s image, or displays a pressed in look.
Might have to subclass it.
Update: You can subclass it, but there’s no need to. Just give yourself a reference to it (myButton, for instance), and then:
[[myButton cell] setShowsStateBy:NSPushInCell | NSCellLightsByContents | NSCellLightsByBackground];
This is pretty cool. Upload an image of a face, and you can run some transforms on it to get alterations.
Try it out at http://www.faceofthefuture.org.uk/
For instance, from two pictures of me, here are some of what I may look like as an “Older” adult:

The one on the top actually looks a little bit like my grandfather, and the one on the bottom looks an awful lot like my father. But older.
Thu 10th Jul 2008
NSSegmentedControl and Core Data.
Posted late in the morning, filed under Objective C.It’s not possible to directly hook up an NSSegmentedControl (or NSSegmentedCell) to a Core Data controlled NSArrayController (or any, for that instance). I wanted to be able to use one of these controllers to allow the user to select one, many or all items from the array.
To define the behaviour a little bit more: You can select the first item in the control (which will be called “All”), and it will select or deselect all of the other items, depending on what it’s state becomes. If you click on another segment, then it will toggle the selection of that segment. If all segments are ON after pressing a segment, then the first segment must also display ON, otherwise it will be OFF.
I did it by creating a new class: SegmentController. (I know, I should put on a prefix…)
SegmentController has two required IBOutlet variables, which refer to the NSSegmentedControl, the NSArrayController, and a property NSMutableIndexSet, which stores, sets and gets the selection indexes (I think this should be indices, but I’ll stick with Apple’s convention). I also have a sortDescriptors array, so that this object can sort the array controller.
There are a couple of limitations, which I might look at how I deal with - for instance, the NSSegmentedControl must have exactly one more segment than the NSArrayController has items. I’m using it to select one or more days, and this number doesn’t change. It should be possible to dynamically create the right number of segments, and populate them with values (I even have a readonly field called shortName set aside in my Day objects for this), but at awakeFromNib the NSArrayController is still empty, and I can’t figure out a nice neat way to force a fetch.
Hooking up the elements in Interface builder is easy. Create the NSArrayController, and set that up however you need to. Do the same with the NSSegmentedControl - at this stage you’ll need to put values in each of the segments. Now, create a new instance of SegmentController (you might need to add the class files to your XCode project first). Connect the two outlets up to the required objects.
Now, in the Bindings Inspector, connect up you’ll want to make the Selection Indexes parameter point to the selectionIndexes model key of your Segment Controller object.
Finally, make the selector of the NSSegmentedControl point to the selectSegment: action of the Segment Controller.
I did notice a slight delay between deselecting one segment and the “All” segment deselecting. A simple optimisation - moving the call to segmentCount out of the loop test and into a local variable made it much smoother.
That should probably do it. It might need a bit of tweaking. You should be able to have multiple instances of this in your project, if it is required. It’s been designed that you’ll need a seperate one for each Segmented Control, as it refers to the objects it is connected to, rather than the sender of the message.
My source code is here: SegmentController.zip