Objective-C for Perl Hackers

I've been messing around with Objective-C off and on for a while now. Whenever I take a break and come back to it, I find myself having to look up some of the same syntax over and over. Some examples would be:


$foo =~ s{bar}{baz}g;


foo = [foo stringByReplacingOccurrencesOfString:@"bar" withString:@"baz"];


$list{'foo'} = 'baz';


[list setObject:baz forKey:@"foo"];

One thing in particular that gets me is the assigning a value to a dictionary, like in the example above. Naming the value *before* the key seems counter-intuitive to me. Luckily Xcode is great with autocompletion, which makes a lot of this easier, but I still find I need reference materials which are more Perlish. To make things easier for myself, I've set up a wiki to map Perl syntax to Objective-C where it makes sense.

Feel free to edit/update/correct the wiki where you see fit. I make no claims of expertise here, but I do find myself referring back to this list and adding to it as I write my own Objective-C code.



Thanks for this, very much appreciated!
Starting from january I am going to give myself a semester of c++ at school. So this comes quite timely for me. :-)

Objective-C is one of the few languages I have never actually used. . . but please tell me that stringByReplacingOccurrencesOfString is a joke and not a real method/function name from what I assume is a standard library?

Seeing things like that makes me want to beat people over the head with their keyboards (specifically, people who come up with method/function/variable names like that).

Leave a comment

About Olaf Alders

user-pic I hack on MetaCPAN, CPAN modules and other fun stuff.