I work on a lot of projects that share significant code between iPhone and Mac versions. This is the beauty of Cocoa. While working on these projects, I’ve bumped into this idiom many times:
#ifdef TARGET_OS_IPHONE
#import <uikit /UIKit.h>
#else
#import <cocoa /Cocoa.h>
#endif
This is almost never correct, and almost always means that someone imported Cocoa.h into a model class. Model classes should never rely on UIKit or Cocoa. They should just import Foundation.h.
There is one interesting exception that we’ve run into: NSImage versus UIImage. These are really model classes, but they’re part of AppKit and UIKit. They have very similar interfaces, so in most code you should be able to interchange them and keep everything portable. What to do?
Read more…
I started implementing a hotkey to regrowl the current song. ishermandom sent me a patch months ago to do this, and I’ve just started integrating it. It’s very small, I just hadn’t done it yet. Since I’ve restructured hotkeys due to the ShortcutRecorder upgrade, I’ve actually had to reimplement it anyway, but really, it’s not complicated.
I also pulled some of the NSLog() statements out, so PB will no longer fill your Console with messages about what song is playing. If you want need this functionality for something, let me know. There are better ways for me to implement it.
Funny, Pandora seems down this morning? The silence is deafening. Even while I’m investigating why the flash player isn’t coming up (even in Safari), I keep hitting my “play” shortcut because its too quiet. I guess I pull out iTunes….
For the last couple of nights I’ve finally gotten back to PandoraBoy work. The backlog of issues has gotten a bit out of hand as I’ve focused on other projects. One thing that has hung me up for a while has been the Hotkey preferences pane, which uses ShortcutRecorder. SR had an IB Pallet that only worked with IB2.5, not IB3, which made working on that panel very difficult. I’ve finally upgraded SR to the latest version, which required a lot of recoding since PB relied SR’s now-deprecated autosave functionality.
The side effect of all of that is that the latest SR requires Leopard, and so now PB requires Leopard. I had planned to wait for SnowLeopard’s release to drop Tiger support, but this accelerates that a bit. It does make my coding a work a bit easier, since 10.5 has many nice developer features.
Drop me a note if you’re still running PB on Tiger. Every other major user of ShortcutRecorder had already gone Leopard-only, which is why they made the move. Tigers are getting pretty rare out there.
Thank you stinkblog, thank you for saving me a great deal of pain debugging this. PandoraBoy work can now continue.
I keep coming across code like this:
newMonster.trueName = [NSString stringWithString:@"New Monster"];
It’s time to say stop it already with the extra +stringWithString:. I haven’t worked out yet where this anti-pattern comes from. Maybe it’s a misunderstanding of some sample code in Kochan? Maybe it’s a Java/.NET thing? I’m not sure. But I see it so often from so many places that it’s clearly something that needs discussing. (The rest of the linked article is good; it just gave me a good example of this issue.)
Read more…
Observing NSNotifications in a view control is a good thing. But remember, just because you’re not onscreen doesn’t mean that you’re not still observing. This is particularly noteworthy on iPhone, where your view can get dropped any time memory is tight and you’re offscreen, but it can bite you anywhere.
ViewControllers, WindowControllers and other UI controllers are often better off registering and uregistering for notifications when they are put on and off the screen rather than when they are allocated and deallocated. This often means that they will need to update their state when put on screen. For example, an icon indicating “connected” might be part of a StatusViewController. When StatusView comes on screen, StatusViewController should update the connected status and then begin observing changes on it. When StatusView goes off screen, StatusViewController should stop observing.
Read more…
Based on a post at StackOverflow. The question was whether Objective-C is only used for development on Mac OS/iPhone and why.
I think ObjC has been isolated to the Apple world through a quirk of history and the nature of proprietary systems.
Read more…