Categories
Development

Objective-C: Don’t make this mistake

Duct Tape, fixer of all things!It’s the little things that can drive a developer to jumping out a window. You plan a solution, code the solution, build the solution, run it, and… it doesn’t work. Most of the time you spot the problem right away, some times you’re left scratching your head, repeating over and over “this looks like it should work?” Of course you know better. It didn’t work, you just can’t see why. I had this problem last night so I thought I’d share with the world, ok not the world, just my electronic brain, so I can look it up later if necessary.

Here’s what I did.

@protocol Blah<NSObject>
-(void)somethingHappened
-(void)somethingElse
@end

Then I implemented the protocol.

@interface NeatoStuff : OtherStuff<Blah>
...
@end

Later, in a different hunk of code I want to send a message to that implementation, so I did something I’ve now done many, many, times. I check to see if the delegate I’ve been given actually answers the message(implements the method) I’d like to send.

SEL delegateSelector = @selector(somethingHappened:);
if ([_delegate respondsToSelector:delegateSelector]) 
{ 
    [_delegate performSelector:delegateSelector];
}

It didn’t work, and I couldn’t see why. Can you? I’ll wait, go ahead and look it over again, I’ll play some Jeopardy music while you work.

Did you spot the problem? It’s one little character. This…

SEL delegateSelector = @selector(somethingHappened:);

Should be this…

SEL delegateSelector = @selector(somethingHappened);

Yep, that’s it. One little “:” had me pulling my hair out, and I just couldn’t see the problem to save my life, at least not for about 10-minutes of outright frustration.

The message doesn’t expect to receive arguments, so the “:” is not necessary. Note to self: Don’t do that again.

Categories
Development iPhone Mobile

Yeah, what he said

Marco Arment: “But the biggest reason why there’s no iPhone SDK on Windows or Linux is that it doesn’t need to exist. The iPhone is the premier platform where the most money is being made. Developers will come to Apple — Apple doesn’t need to come to developers. (Google does, as the underdog.) It’s the same reason why there’s no OS X or Linux port of Microsoft Visual Studio, and you don’t see a lot of Mac owners yelling at Microsoft for not porting its sophisticated development environment to their chosen operating system.” – I really like this Marco guy. He’s about as blunt as can be, but he makes fine points. He’s also the creator of Instapaper, an application that’s quickly becoming my favorite little utility.

Categories
Development Indie Mac

Mac Bits for Sale?

Matt Legend Gemmell: “I want to solicit some feedback on the idea of selling source code for the iPad/iPhone and/or Mac platforms. It’s something that’s commonplace (and popular) on other platforms like .NET and Java, but for whatever reason it’s never taken off on the Mac. I think that there’s potentially a reasonable market, particularly for iPhone/iPad, and I’d be interested in your thoughts.” – It’s odd there isn’t more of this in the Mac world. There’s definitely a whole lot of free, very well designed, Mac and iPhone source code floating around out there. Matt’s very own MGTwitterEngine or Gus Muller’s FMDB to name a couple.

I, for one, would welcome high-quality, supported, fully baked component bits for the Mac, iPhone, and iPad. It’ll make my life easier and allow me to focus on creating apps by not having to create as many foundation pieces.