Mac Development
Over the last few weeks I have been using what spare time I have to learn Objective-C with Cocoa. While Objective-C has been easy coming from a PHP background the Cocoa frameworks have not. There are things in Cocoa Programming that I have to worry about that I did not have to even think about in PHP. Just a few of those things are Memory Management, The Main Run Loop, etc. I have never had to worry about any of that with PHP because the scripts are run and then destroyed. They do not take up memory and just hang around all day long. However if you are not careful with Objective-C you will have a lot of memory eaten up really quick.
Now I have been working on small apps mainly using NSBezierPath so that I can learn how to draw squiggles and straight lines by clicking the mouse just like you would with the pencil/brush or line tool in a paint application. While this really is boring to me I am being instructed to do this by a friend who is helping me along the Cocoa path.
So here's a plug for him.
Steven Degutis
http://thoughtfultree.com/
If you want to support me learning Cocoa I cannot say buy my products but you could go buy his. He is a great developer and has been very helpful along the journey. His apps are very nice and are rather inexpensive also. You can get all of his apps for around $30 (at the time of writing this) or buy them individually.
Now as I mentioned you have to keep memory management on your mind while developing Cocoa applications that is unless you are leveraging the power of Leopard and using the Garbage Collector, however I have been trying to stay away from that currently so that I can learn how to manage the memory myself. I feel that this is a necessary thing to know. If you want do develop only for Leopard going forward then you would be fine not knowing about memory management but at that rate don't even think about developing for the iPhone / Touch because they do not have the garbage collector ability.
So as I was saying managing memory is not something you have to do in PHP, let's take a look at the differences.
In PHP you could do the following
-
$var = 5;
-
$var = 1;
-
echo $var;
In the above code the obvious answer is that $var = 1. The value of 5 has been overwritten. However this is completely different with Objecitve-C since everything is a pointer. For instance
-
NSString *Foo = @"First String";
-
Foo = @"Another String";
-
NSLog(@"string = %@", Foo);
In the above you would expect that string = Another String and it does... However what happens to the first string we created? Is it overwritten? Nope instead when Another String is created Foo is redirected to point at that memory location just forgetting about the other strings memory location. There is where the memory leaks come into play that we did not have to worry about with PHP.
Anyway as I learn I plan to add articles to my MacDev Articles section both for documenting things for myself and hopefully to help others down the learning path as well.






Steven
Thanks for the kind words! This is an interesting article, too, and sums up pretty nicely the differences between ObjC and PHP in terms of memory. Nice job
[Translate]