Cocoa Bindings

Wil Shipley of Delicious Monster pointed out that the challenge from Chapter 4 of Aaron Hillegas’ book “Cocoa Programming for Mac OS X” can be easily solved by using Cocoa Bindings, rather than using the more typical target/action approach. When I was going through Aaron’s book, I hadn’t been exposed to Cocoa Bindings yet, since those aren’t introduced until Chapter 6.

I thought, ‘Huh, yep, that way looks pretty easy,’ but there are a few steps missing from Wil’s description that are critical if it’s to work right. I admit I don’t understand all of them; I’m busy reading the Cocoa Bindings and Core Data documentation to try to fill in my understanding.

So here’s what I did:
Add a controller class for the methods. This is implied and easy to see. I called mine AppController.

Remove the button from the Window in IB; you don’t need it anymore!

Drag an NSObjectController instance from the palette to your NIB. Change the class name to match the controller you created in step 1.

Now, your object controller should show up in the Bindings -> Value -> Bind To inspector when you’ve got either your input or your output text field selected. Without adding the NSObjectController, I floundered around for a minute or two trying to figure out what to do at this stage of trying to follow Wil’s example.

For some reason I had to modify Bindings -> Availability -> Editable and Enabled for the input text field; I set them both to isEditable on NSObjectController. Finally, I selected the NSObjectController in my NIB and set its Editable attribute to True. Now when I run the app, I can enter characters in the input field, tab or return out, and the count of characters updates to the output field. Pretty cool!

I think someone should sponsor a contest to see who can make the most useful application with no code.

Tagged | Comments Off on Cocoa Bindings

Cynicism on Pro Cycling

So, now that Vinokourov has won the 2006 Vuelta a España, how long till we find out he’s been doping?

Tagged | Comments Off on Cynicism on Pro Cycling

Riding with a toddler

Here’s what’s involved in a 14-mile bike ride with Elizabeth, a two-year-old. This is why I prefer riding from home if possible:

•Pump up tires of bicycle and trailer
•Replace rear skewer of bicycle wheel with skewer and trailer mount
•Attach bike rack to car
•Collapse trailer
•Remove trailer attachment arm and flag; place in trunk of car
•Pick up the trailer and place it on the rear window of the car
•Roll it up and over the rear crossbar of the rack
•Secure it between the crossbars with luggage straps
•Remove front wheel of bicycle
•Place bicycle on bike rack and rear wheel in trunk
•Gather helmets and water for both rider and passenger
•Apply sunscreen and get dressed to go
•Drive to start location
•Perform steps 10 to 4
•Ride!
•Perform steps 4 to 10 again
•Drive home
•Perform steps 10 to 4

Tagged , | Comments Off on Riding with a toddler

Problems with Cocoa Core Data ‘Core Recipes’ Example

I’m working on a couple of applications using Cocoa and Core Data. I’m familiar enough with the KVO, KVC, and things like NSArrayController to write the app without Core Data, but it’s such a cool tool and I figured the data modeling tool and the data store would save me some time.

For some reason, examples of Core Data applications seem pretty rare on Google, and whenever I try to search for them I have to filter out a lot of crap about Weight Watchers. Apple does have one decent example application called Core Recipes, a recipe application built on Core Data. I downloaded that, opened it up in XCode, let it upgrade the project file, built, and ran it. No recipes showed up in the app and I knew it came with some sample data and included a spotlight importer for slightly more sample data, so I read the meager documentation included with the demo to make sure I’d put it in the right places.

I quit the app and fired it up again. This time, the app loaded, but I couldn’t get focus to the app window or bring it to the front (“make key and order front”) using the mouse. When I moved all the other windows out of the way so CoreRecipes was the only thing left, I found I still couldn’t get focus to it, and couldn’t even use the menu bar. I had to force it to quit using the Stop button in XCode.

I think it has something to do with the data store files. It uses the Core Data XML data store by default. It expects its main library to be in ~/Library/Application Support/CoreRecipes/CoreRecipesLibrary.crx, and is supposed to use the Spotlight Importer to find other available recipe files.

Whenever there is a CoreRecipesLibrary.crx in the Library directory, the app exhibits this frozen behavior on launch. If I delete that file, it launches fine. If I then add chefs, ingredients, and recipes of my own, save and then quit, a CoreRecipesLibrary.crx is created in the standard location, and the next time I launch it, the app exhibits the freezing behavior.

When I pause the app in the debugger, the stack trace goes like this:

#0 0x9000b268 in mach_msg_trap
#1 0x9000b1bc in mach_msg
#2 0x907dbb78 in __CFRunLoopRun
#3 0x907db47c in CFRunLoopRunSpecific
#4 0x931eb740 in RunCurrentEventLoopInMode
#5 0x931eadd4 in ReceiveNextEventCommon
#6 0x931eac40 in BlockUntilNextEventMatchingListInMode
#7 0x936eeae4 in _DPSNextEvent
#8 0x936ee7a8 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
#9 0x936eacec in -[NSApplication run]
#10 0x937db87c in NSApplicationMain
#11 0x0000efa8 in main at main.m:13

I can’t imagine I’m the only one having this problem. Any ideas?

Tagged | 3 Comments

Losing stuff and finding it again

Since Elizabeth has become mobile and often wants to play with the same things she sees Andrea and I using, I’ve become much more careful about where I put certain things, especially if they’re delicate or I use them frequently. I have two shelfs in our big cabinet in the office area off our kitchen where I keep most of my daily-use and fragile items, like my mobile phone, wallet, keys, camera, Garmin Edge GPS bicycle computer, and Hipster PDA.

Other things have other homes. The chest strap for the heart rate monitor (HRM) that goes with the Edge — when I finish a ride or a run, the strap will usually be pretty salty from sweat, so I wash it off and hang it up on a towel rack in the bathroom to dry, then I put it either with my bicycle helmet, or in the drawer with the rest of my biking stuff.

I’m glad Elizabeth’s curiosity helped to coax me in to this habitual behavior. I rarely spend any time these days looking for where I left something, because I always leave the things in the same place.

At least, that’s the theory. Practice isn’t quite as nice. Tuesday I woke up early to go on a run. The chest strap wasn’t on the drying rack, so I went to get it from the closet where I keep my bike helmet, and it wasn’t there either, so I looked in the drawer with my biking clothes. No luck!

I spent the next half hour tearing through the main floor of the house looking for the chest strap. I even looked in the garage with my bikes, and inside the car! Nowhere! Keep in mind this is all before 6 AM, so Andrea and Elizabeth are trying to sleep through my increasingly grumpy search. Eventually I gave up and went running without it.

Today, Andrea and volunteering for her Le Leche League group, so Elizabeth and I are doing a little bit of organizing around the house. I decided to go through my shelves in the big office cabinet, and saw the box for the replacement Edge sitting in the back of the top shelf. I pulled it out and thought, “hm, this is quite heavy, I wonder what’s in there?” As I opened it up, I remembered Garmin had sent me a complete replacement Edge 305, including a chest strap for the HRM! Bonus!

As I pulled the brand new HRM strap from the box, my eyes settled on the bottom shelf, where the old HRM strap had probably been sitting this entire time.

Posted in General | Tagged , | 1 Comment