0

I am learning iphone dev now. Now I am reading book "iPhone 4 Development". During reading this book, I am confused about some syntax about objective-c used in this book. Ok, here are my questions:

  • Link framework v.s. header file

At the end of chapter 7 of this book, the book mentions "link project to framework". In this book, it links to project to AudioToolbox.framework. I am wondering why not just add the header file instead of linking framework? What's the difference between linking to a framework and adding a header file?

  • "self" in dot & "[]" expression

In chapter 9 of this book, sample code uses dot operator and square bracket expression several times, for example: SecondLevelViewController *controller = [controllers objectAtIndex:row]; and SecondLevelViewController *nextController = [self.controllers objectAtIndex:row]; I think these two sentences have the same function. So when should I use "self"? When not?

Thanks, Sam

Sam Wei
  • 99
  • 4
  • 11
  • 1
    It would make more sense making two different questions (and this would have allowed you to find that your question is already answered) by which I mean, remove the part about the self operator (no use making it a question now you know it's a duplicate) – Kheldar Sep 01 '11 at 14:21
  • Here's the answer btw http://stackoverflow.com/questions/4018459/understanding-self-in-objective-c not flagging because of the first part. – Kheldar Sep 01 '11 at 14:27
  • I think the questions are far enough apart to fly. The community is free to override me, however. – Tim Post Sep 01 '11 at 14:38

2 Answers2

0

Linking framework, just as in Visual Studio for Windows, tells your compiler where to find the libraries.

You then add the relevant include/import calls so that the compiler finds your class from imported library in the source, goes up the import/include, goes and hits the library, and back (more or less, it doesn't matter the exact behavior).

The question about self is a clear duplicate, check SO for "objective-c self"...

Kheldar
  • 5,361
  • 3
  • 34
  • 63
0

When you write self.outlet = nil the method [self setOutlet:nil]; is called. When you write outlet = nil; you access variable outlet directly.

if you use @synthesize outlet; then method setOutlet: is generated automatically and it releases object before assigning new one if you declined property as @property (retain) NSObject outlet;.

Moved from here

Community
  • 1
  • 1
Nekto
  • 17,837
  • 1
  • 55
  • 65
  • Thanks, but I still don't get why use "self" in [self.controllers objectAtIndex:row]; ? Is it neccessary? – Sam Wei Sep 01 '11 at 14:44
  • If you have variable `_controllers` that was syntesized using `@synthesize controllers = _controllers`, then you can only type `[_controllers smthHere];` or `[self.controlles smthHere]`. – Nekto Sep 01 '11 at 14:46
  • Yes, @Nekto, you're right. Thank you! Also I found an article on through stackoverflow which said the same thing as you did:[link](http://useyourloaf.com/blog/2011/2/8/understanding-your-objective-c-self.html?lastPage=true#comment14967851) – Sam Wei Sep 01 '11 at 16:02