关于objective-c的两个问题:框架链接和“自我”在点和方括号表达式
我现在正在学习iphone开发。现在我正在看《iPhone 4开发》一书。在阅读这本书的过程中,我对本书中使用的一些关于 Objective-C 的语法感到困惑。好的,这是我的问题:
- 链接框架与头文件
在本书的第7章末尾,书中提到了“将项目链接到框架”。在本书中,它链接到 AudioToolbox.framework 项目。我想知道为什么不只添加头文件而不是链接框架?链接到框架和添加头文件有什么区别?
- 点与点中的“自我” “[]”表达式
在本书第 9 章中,示例代码多次使用点运算符和方括号表达式,例如: SecondLevelViewController *controller = [controllers objectAtIndex:row];
和 SecondLevelViewController *nextController = [self.controllers objectAtIndex:row];
我觉得这两句话的作用是一样的。那么什么时候应该使用“self”呢?什么时候不呢?
谢谢, 山姆
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
链接框架与 Visual Studio for Windows 中一样,告诉编译器在哪里可以找到库。
然后添加相关的包含/导入调用,以便编译器从源中的导入库中找到您的类,向上导入/包含,进入并命中库,然后返回(或多或少,确切的名称并不重要)行为)。
关于自我的问题显然是重复的,请检查“objective-c self”......
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"...
当您编写
self.outlet = nil
时,将调用方法[self setOutlet:nil];
。当您编写outlet = nil;
时,您可以直接访问变量outlet。如果您使用@synthesizeoutlet;,那么方法
setOutlet:
会自动生成,并且如果您拒绝将属性作为@property(保留)NSObject,它会在分配新对象之前释放对象插座;
。移自此处
When you write
self.outlet = nil
the method[self setOutlet:nil];
is called. When you writeoutlet = nil;
you access variable outlet directly.if you use
@synthesize outlet;
then methodsetOutlet:
is generated automatically and it releases object before assigning new one if you declined property as@property (retain) NSObject outlet;
.Moved from here