OBJ-C/Cocoa: Programming for OS X

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
FACM
Posts: 303
Joined: Thu Aug 09, 2007 6:40 pm UTC

OBJ-C/Cocoa: Programming for OS X

Postby FACM » Sun Nov 09, 2008 10:34 pm UTC

I've been trying to teach myself Objective-C/Cocoa lately, as I've been looking at learning to program for the iPhone/iPod Touch. I picked up a couple books on Xcode 3 and Obj-C 2.0, and have been going through them fairly slowly. Apple's developer documentation is not nearly as nice as it should be, and I was wondering if anyone else knew offhand about a good site to learn such things.

[Semi-related: Personally, I think Visual Studio is a far better environment for developing apps than Xcode. This hasn't stopped me from trying to learn it, but it does irritate me some.]

User avatar
Vault
Posts: 169
Joined: Mon Nov 10, 2008 5:00 pm UTC
Location: Just past the event horizon
Contact:

Re: OBJ-C/Cocoa: Programming for OS X

Postby Vault » Wed Nov 12, 2008 4:14 am UTC

I have been wanting to do the same for a while now. Time and short attention spans keep getting in my way.

That being said, I suggest you check out http://www.cocoadevcentral.com/ if you haven't already. There are some good tutorials on that site and links to several other tutorials. One that I recently found to be quite good is Cocoa for Scientists. As the name implies it's intended for scientists (who would be leaving something like C or Fortran) and it is fairly easy to understand. There is also a free book here that is rather basic introduction. There are some more advanced topics on the site as well, but you need to know Obj-C and Cocoa first for them to really be of much help. Another decent tutorial is at wikibooks and I like this one because its method of teaching is through a large example (making a somewhat sophisticated drawing program). The only problem is that the code given in the tutorial doesn't quite match up with the code in the provided files, meaning that if you follow the steps it is very possible that your program won't work.

It should be noted though, that many of the tutorials you will find deal with Xcode 2 and the previous version of Interface Builder, which is considerably different from the current one. It's not too hard to figure out the changes though, once you've seen how things are done in each version.

As far as Xcode versus Visual Studio goes, I don't really know. I've only ever used Xcode and overall I like it. Interface Builder is easy as sin and it seems to be a few steps above and beyond any other GUI builder that I have ever seen.

Catfish_Man
Posts: 13
Joined: Wed Oct 01, 2008 1:41 am UTC

Re: OBJ-C/Cocoa: Programming for OS X

Postby Catfish_Man » Wed Nov 12, 2008 8:54 am UTC

Aaron Hillegass's book is the usual recommendation for new Cocoa programmers. Anything beyond what it covers and you'll be better off with Google and/or irc than a book, in general. Another good way to learn is to get involved in open source projects. My personal bias urges me to suggest Adium here, but it can be a bit of a learning cliff at first.

User avatar
FACM
Posts: 303
Joined: Thu Aug 09, 2007 6:40 pm UTC

Re: OBJ-C/Cocoa: Programming for OS X

Postby FACM » Thu Nov 13, 2008 1:10 am UTC

@Vault: IB is not as easy as VS.NET, even if you're more experienced with IB. If you've got Windows, download one of the Visual X Express installers from Microsoft's website for free and check it out to compare.

For a quick references, compare making a button that makes a Hello World label visible on a small window. In Xcode, thats setting up the .h file to have a input point for the button, an output to the label, connecting them in IB, then going to the .m file to write in the label.setVisible [or equivalent] property to True. In VB.Net, drag the button and label on the window, double click on the button to open the onClick event function, then type label.Visible = true. It's much smoother and intuitive for most any purpose. I'm sure there are cases where Xcode makes more sense, but none come to mind for me.

Karrion
Posts: 92
Joined: Fri Jun 22, 2007 12:14 am UTC
Location: Melbourne, AU

Re: OBJ-C/Cocoa: Programming for OS X

Postby Karrion » Thu Nov 13, 2008 10:00 am UTC

I know nothing of Cocoa, so I'm not sure if it's good for a beginner, but a friend of mine writes Cocoa With Love. (/shamelessplug)

User avatar
Vault
Posts: 169
Joined: Mon Nov 10, 2008 5:00 pm UTC
Location: Just past the event horizon
Contact:

Re: OBJ-C/Cocoa: Programming for OS X

Postby Vault » Thu Nov 13, 2008 9:46 pm UTC

As I said, my only experiences are with Xcode and IB and I am not in a position where I can try out Visual Studio, though from what I've been reading it sounds pretty cool. If I could try it out I would.

As far as Cocoa goes I'm gonna have to take a look at that book. I'm still learning how things work and it seems like it is just what I need. I think that contributing to an open source project would also probably be a good way of getting experience, and I'll look into that as well.

I'd also like to mention that Apple's documentation is not the best. In my opinion the 'cocoa fundamentals guide' that they have is impossible to read and come away with any form of enlightenment and while it undoubtedly covers all of the technical details very well, it is rather boring and lacks examples.

Catfish_Man
Posts: 13
Joined: Wed Oct 01, 2008 1:41 am UTC

Re: OBJ-C/Cocoa: Programming for OS X

Postby Catfish_Man » Fri Nov 14, 2008 9:44 pm UTC

FACM wrote:In VB.Net, drag the button and label on the window, double click on the button to open the onClick event function, then type label.Visible = true. It's much smoother and intuitive for most any purpose. I'm sure there are cases where Xcode makes more sense, but none come to mind for me.


Not to get into an API flamewar here, but how does VB.net handle the equivalent of Cocoa's "first responder" concept? In IB the first responder icon is essentially a proxy for the responder chain (although it's actually implemented by just setting the action's target to nil), so the message is sent to whatever control is currently active; very handy for things like the copy and paste menu items.

mrkite
Posts: 336
Joined: Tue Sep 04, 2007 8:48 pm UTC

Re: OBJ-C/Cocoa: Programming for OS X

Postby mrkite » Sat Nov 15, 2008 8:04 am UTC

Catfish_Man wrote:Not to get into an API flamewar here, but how does VB.net handle the equivalent of Cocoa's "first responder" concept? In IB the first responder icon is essentially a proxy for the responder chain (although it's actually implemented by just setting the action's target to nil), so the message is sent to whatever control is currently active; very handy for things like the copy and paste menu items.


I'm not sure about VB.net but I'm assuming it works the same as C# etc. It doesn't use a message-based system, it uses callbacks.

User avatar
FACM
Posts: 303
Joined: Thu Aug 09, 2007 6:40 pm UTC

Re: OBJ-C/Cocoa: Programming for OS X

Postby FACM » Sat Nov 15, 2008 9:21 pm UTC

If you're using the First Responder as a 'hey, the window's open, do your thing here' call, the .NET eqivalent is the FormOpen or the Load property, depending on which version you're using. This is the function that runs when the window is opened for the first time.

Catfish_Man
Posts: 13
Joined: Wed Oct 01, 2008 1:41 am UTC

Re: OBJ-C/Cocoa: Programming for OS X

Postby Catfish_Man » Sun Nov 16, 2008 5:16 pm UTC

FACM: That would generally be done in -awakeFromNib; the responder chain is (conceptually at least) a linked list of objects, not an event or method call.

User avatar
kovan
Posts: 169
Joined: Mon May 26, 2008 7:40 pm UTC
Location: Toronto
Contact:

Re: OBJ-C/Cocoa: Programming for OS X

Postby kovan » Mon Nov 24, 2008 8:49 pm UTC

For me there's been a lot of trial-and-error. It's been mostly trying to forget everything I know and then get into this message stuff. Coming from a Java/C++/.NET background it was a bit of a system shock to jump into Obj-C.

The Apple documentation is pretty horrible unless you know exactly what you're looking for and just need a list of parameters or something, information on google is not always helpful because a lot of the stuff will either only apply to OSX development or it will be some blog from 2005 about developing Java apps for the iPhone via safari or something retarded like that.

Use the demo code I would say. Also if you think you've experienced the most retarded aspect of Objective-C, you probably haven't because there's always something more retarded waiting around the bend for you (can you tell I'm a little sour on Objective-C right now?) I think I actually prefer VB.net's OO implementation over Obj-Cs.


Oh, the only way of parsing XML on the iPhone is by using their idiotic SAX-style event-driven bullshit.

Catfish_Man
Posts: 13
Joined: Wed Oct 01, 2008 1:41 am UTC

Re: OBJ-C/Cocoa: Programming for OS X

Postby Catfish_Man » Tue Nov 25, 2008 8:44 am UTC

kovan wrote:Also if you think you've experienced the most retarded aspect of Objective-C, you probably haven't because there's always something more retarded waiting around the bend for you (can you tell I'm a little sour on Objective-C right now?) I think I actually prefer VB.net's OO implementation over Obj-Cs.


What issues are you running into? ObjC isn't a perfect language by any means, but if you're hating it that much there's likely something you're missing.

User avatar
kovan
Posts: 169
Joined: Mon May 26, 2008 7:40 pm UTC
Location: Toronto
Contact:

Re: OBJ-C/Cocoa: Programming for OS X

Postby kovan » Wed Nov 26, 2008 2:44 pm UTC

Catfish_Man wrote:
kovan wrote:Also if you think you've experienced the most retarded aspect of Objective-C, you probably haven't because there's always something more retarded waiting around the bend for you (can you tell I'm a little sour on Objective-C right now?) I think I actually prefer VB.net's OO implementation over Obj-Cs.


What issues are you running into? ObjC isn't a perfect language by any means, but if you're hating it that much there's likely something you're missing.



I think my issue is mostly with the OO implementation. I'm getting used to it now but I'm coming from mostly a Java-style OO background so it's not my favourite way of doing it.

Catfish_Man
Posts: 13
Joined: Wed Oct 01, 2008 1:41 am UTC

Re: OBJ-C/Cocoa: Programming for OS X

Postby Catfish_Man » Wed Nov 26, 2008 7:28 pm UTC

Fair enough. It seems almost identical to Java's to me (single inheritance + interfaces, class-based, late bound), but maybe I have a weird perspective.

gormster
Posts: 233
Joined: Mon Jul 23, 2007 6:43 am UTC
Location: Sydney

Re: OBJ-C/Cocoa: Programming for OS X

Postby gormster » Thu Nov 27, 2008 1:04 am UTC

Obj-C has a number of exceedingly stupid features, like the square-brackets messaging thing that just shits me up the wall sometimes. However, once you get used to the concepts - everything is a method call, every object sends its events/notifications as methods to its delegate, the sheer number and layout of the bizarre function names - it's actually a fairly useful tool. It's less than stellar for RAD - in fact, if you want your development to go smoothly, it's probably a good idea to (a) map out your MVC stuff on paper - nothing serious, just what your interface needs to tell your program - remember, under OSX they are separate entities - and (b) design your interface first. It took me a while to realise that one. But it serves as a nice middle ground between RAD and structured development.

I've been coding in Obj-C for a while now, and I have to say the inclusion of dot-notation properties is really very useful, especially in things like Core Animation layers where you could be accessing something tens of layers deep. That would be a lot of fucking square brackets. Anyways Obj-C isn't so bad once you get used to it.
Eddie Izzard wrote:And poetry! Poetry is a lot like music, only less notes and more words.

User avatar
kovan
Posts: 169
Joined: Mon May 26, 2008 7:40 pm UTC
Location: Toronto
Contact:

Re: OBJ-C/Cocoa: Programming for OS X

Postby kovan » Thu Nov 27, 2008 3:34 am UTC

Catfish_Man wrote:Fair enough. It seems almost identical to Java's to me (single inheritance + interfaces, class-based, late bound), but maybe I have a weird perspective.


Are there actually interfaces in obj-c (I mean interface in the java/C# sense)? the @interface stuff seems more like abstract classes than actual interfaces to me.

Catfish_Man
Posts: 13
Joined: Wed Oct 01, 2008 1:41 am UTC

Re: OBJ-C/Cocoa: Programming for OS X

Postby Catfish_Man » Thu Nov 27, 2008 7:01 am UTC

Yeah, @protocol is the equivalent.

Karrion
Posts: 92
Joined: Fri Jun 22, 2007 12:14 am UTC
Location: Melbourne, AU

Re: OBJ-C/Cocoa: Programming for OS X

Postby Karrion » Sat Nov 29, 2008 12:13 am UTC

kovan wrote:Oh, the only way of parsing XML on the iPhone is by using their idiotic SAX-style event-driven bullshit.


You can apparently use libxml2 on the iPhone

hooktail154
Posts: 13
Joined: Wed Jan 27, 2010 7:21 pm UTC

Re: OBJ-C/Cocoa: Programming for OS X

Postby hooktail154 » Sun Jan 31, 2010 1:11 am UTC

Having programmed in Obj-C and used IB to great result successfully, and having tried to do complex view nesting and layouts in VB, I have found it completely illogical and impossible, seeing as the layout editor doesn't support many of the functions I consider in IB to be extremely basic

But I might give it another try soon, you never know, it could finally make sense to me, MAYBE

Considering everything, it is EXPONENTIALLY easier to write apps on a Mac, like databases, Command Line GUIs, and (best of all) xkcd readers

User avatar
kovan
Posts: 169
Joined: Mon May 26, 2008 7:40 pm UTC
Location: Toronto
Contact:

Re: OBJ-C/Cocoa: Programming for OS X

Postby kovan » Fri Feb 05, 2010 2:40 pm UTC

I really enjoy Cocoa, but I really hate Interface Builder.

EDIT: I just saw my post from over a year ago... LOL boy have things changed.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 10 guests