views:

46

answers:

4

Hi,

Yes I've seen questions like these before but they're all for people who basically want to start from scratch. I come from AppleScript Studio (for those who do not know it, it's AppleScript in Xcode with IB etc.). The only things new to me are related to interface and implementation files. In my code I've already written 2000+ lines of ObjC, so it's not the syntax. But I fail to understand inheritance, accessing variables from other class files, etc.. The way I use ObjC is having one NSObject in IB which its class is changed to something new by me and then all my code is written in that one implementation file. My biggest problem is finding out how to access parameters from other classes.

So do any of you have any tips on where to start? Normally I'd start from scratch with a book but I seem to fairly be able to write code as long as it's located in one big file...

Thanks for your help.

A: 

I would suggest that your "problem" has nothing to do with Objective-C and everything to do with object-oriented design. I would get a good OO book such as Design Patterns (Gamma, et. al.), Object-Oriented Software Construction (Meyer), etc. I would suggest not using Objective-C for this part of your education (use Java), because you will easily confuse software design with learning the Cocoa (and other) frameworks. Once you get a leg up on this, you can then explore how to apply in objective-C, how Cocoa framework uses object-oriented techniques, etc.

And enjoy!

PS: The ability to write code is not your goal, particularly if the code is located in one big file.

Bill
fuzzy lollipop
I agree with your general premise that his problem is that he knows nothing about software design, but your actual advice strikes me as very wrong. Design patterns are helpful in design, but you need a foundation before those tools are useful to you. And Cocoa encourages the use of certain design techniques, so I don't see why learning Java would be more beneficial to someone who wants to know how to design Cocoa programs.
Chuck
Because he has been living in AppleScript Studio for a time; moving away from the Cocoa framework is exactly what he needs. [Although I suppose I agree with the GOF comment by fuzzy]
Bill
So you all agree that the problem lies into object-oriented design? In AppleScript Studio you just have IB and an AppleScript file and when you think that you want to use another AppleScript in your project, than you can create one.. It's quite easy. But the first thing that always gets my attention is when I look at some ObjC source code and the amount of files they're using.. In AppleScript Studio I used maximum 10 AppleScripts. 10 seems so little in ObjC.
+2  A: 

I've had excellent luck with these Cocoa Dev Central tutorials, and they're short and well-organized enough that you should be able to skip over any parts that you feel you already know.

  1. http://cocoadevcentral.com/articles/000081.php (C)
  2. http://cocoadevcentral.com/d/learn_objectivec/ (Obj-C)
  3. http://cocoadevcentral.com/d/learn_cocoa/ (Cocoa part 1)
  4. http://cocoadevcentral.com/d/learn_cocoa_two/ (Cocoa part 2)
  5. http://cocoadevcentral.com/articles/000082.php (Style part 1)
  6. http://cocoadevcentral.com/articles/000083.php (Style part 2)

It sounds to me like you can probably skip the first (C), but it couldn't hurt to skim it. The second (Obj-C, especially Part 5, Designing a Class Interface, and onward) is where the answers to your immediate questions lie. Good luck!

andyvn22
Thanks pal! It's going to be a BIG help!
+1  A: 

I can relate to your confusion on those particular aspects of Objective-C coding. The notation used to pass arguments and access object attributes is quite different than other C-type environments. Creating your object properties with the @synthesize directive (when applicable) can go a long way to ensuring consistent behavior. Also to keep in mind that Obj-C uses the 'super' keyword to access base objects instead of 'base'.

When I was first learning Obj-C I learned from this Apress guide and felt it to be a helpful transition from a C/Java background to understanding Obj-C's syntax and object/inheritance model.

hqrsie
Thank you. I'll certainly take a look at it. I know I need @synthesize for accessing those variables but I don't know how it works, when it's really needed, when not. The 'super' thing has got to do with inheritance I guess so that's where I'm failing too..
+1  A: 

Although you understand Interface Builder, it's very clear that you don't understand Objective-C or Cocoa very well at all. You need to stop flailing around and give yourself a firm grounding in the language and frameworks. The only way to do this properly is to start at the beginning.

You should start by learning Objective-C properly. In my opinion, the best way to to this is to read Stephen Kochan's superb Programming in Objective-C 2.0. This will teach you how to write Objective-C properly and explain object-oriented coding, class inheritance and so on. You should read the book cover to cover and do all the exercises.

You should then read Aaron Hillegass' Cocoa Programming for Mac OS X which will teach you how to take Objective-C and marry it to Interface Builder and the Cocoa frameworks to produce working Cocoa apps.

You should also read Cocoa Design Patterns which will explain what the design patterns in Cocoa are and how to use them to your advantage to write Cocoa apps the right way.

Rob Keniger