Articles for April 2008
Cocoa: Key-Value Observing
KVO is a simple addition to KVC. When you write to an object using a key or key path, it is of course Cocoa doing the look-up — and therefore Cocoa can spy on ("Observe") all changes to objects that use KVC. Cocoa shares this wiretap intelligence with you, if you ask.
KVO is simply a mechanism whereby one object registers an interest in another object, and is automatically notified by Cocoa whenever a change is made. The method is addObserver:forKeyPath:options:context:; you call it on the instance you wish to observe, and when a change does occur, you'll receive an observeValueForKeyPath:ofObject:change:context: callback. I'm not going to go into detail on these — check out the official KVO documentation.
Hello The Speed Bump
Or rather, bonjour le bompe de vitesse, or, er, something. What am I blathering about? Okay, let's say you were going to use Bonjour (aka The Technology Formerly Known As Rendezvous, aka zeroconf) to do some HTTP, you might be tempted to simply take the Bonjour Hostname, stick it in a URL, and use it like that. For instance, if your Bonjour Service Browser finds Wooji.local. you might be tempted to fetch http://Wooji.local./some/url.html.
Wurgh
So, we released Voluminous, and then what? Well, then I came down with a bad head-cold-flu-type-thing, and have spent the last couple of days pottering about failing to make any progress on the new project and devoting my minimal energy to answering emails about Voluminous, putting out a small update, and then going back to hide under blankets.
I'm starting to come out of it now, so I should have another part of our ongoing Cocoa tutorial up in a day or so. See you soon!
Introducing Voluminous
Well, after a lot of hard work and nervous tension, we've released Voluminous, our new all-in-one Internet Librarian. What does it do? Well, it finds books for you, on the Internet. Free ones. Over 20,000 of them, actually. All legal, by the way — they're in the public domain (it checks). It makes a catalogue, and you can search it in a variety of ways, download the ones you want, and turn them into nicely-formatted books (they start off as plain text) that you can read or print or turn into PDFs or send to friends or search to find that elusive quote or... well, you get the idea, I hope.
Cocoa: Key-Value Coding
KVC is quite simple: it's a way to access an object's members by their name, as a string, rather than accessing them directly — it's comparable to Python's getattr(); it has a clunkier syntax, but more features.
If you're already familiar with Python's getattr() you can probably skip down to Key Paths, but otherwise:
Let's say you have a Colour class with three instance variables, red, green, and blue. Obviously these can be accessed in the usual way: myColour->red in C++, myColour.red in Python, [myColour red] in Objective-C — all of these directly specify the red component, in code.
NSTokenField Tip
Here's a small problem I ran into recently, and the solution. I don't know if it's a Cocoa bug, or expected behaviour and I just didn't pick up on that from the documentation, but either way it's worth drawing attention to.
NSTokenField is the widget you see in Apple Mail and Automator, that looks like a normal text input field, but can also include blue lozenge-shaped "tokens". They're quite easy to use — just drop them in like a normal text box, then implement a delegate to handle callbacks for autocompletion, getting display names, and handling token menus.
Sorry: Hosting Hiccup
Sorry for the downtime yesterday, we were offline briefly due to changing IP address and getting SSL set up.