Two questions about objective-c: framework link and "self" in dot & square bracket expression
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 objec开发者_C百科tAtIndex:row];
I think these two sentences have the same function. So when should I use "self"? When not?
Thanks, Sam
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"...
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
精彩评论