Objective-C Primer(2)Private Methods and Class Properties
- Author: 柳大·Poechant(钟超)
- Email: zhongchao.ustc#gmail.com (# -> @)
- Blog:Blog.CSDN.net/Poechant
- Date: May 6th, 2012
1 What the relationship between C and Objective-C?
If you want, you can just program in C language style and syntax, and there will be no error or warning if you never make mistakes of C programming. Therefore, you must say: Getcha!
Yes! Objective-C is a super set of C language, just like C++ to C.
2 No private methods declaration in .h file?
Yes, you are right. But think it twice. Is it more reasonable to hide or ignore private methods declaration in header file? Every invoker just appears in member methods of .m source code files, so it’s unnecessary to give any clue for private methods in header file.
Do you know how to hide private methods declaration in C++? (Give you a hint: pimpl idiom.)
Now I will show how to do that. The.h
is still the one I introduce in Objective-C Primer (1) Get started! But how about.m
file?
#import "TestClass.h"
@implementation TestClass
@synthesize foo;
-(void)privateMethod
{
NSLog(@"I'm a priavte method, named 1");
}
-(void)someMethod
{
NSLog(@"some method got called");
[self privateMethod];
}
But notice that there will be a warning if you invoke a private method below the invoker method. Just like the following.
3 Class properties
As we know at present, in Objective-C, a class consists of an interface which is visible for external users and an implementation for class behavior details.
What about properties?
There are some many identifiers for properties, which will be messed up.
-
retain
will increase the reference counter, and of course set the value of the pointer.
-
assign
does not increate the reference counter, but also set the value of the pointer.
-
copy
will create a new object, which is the same as the source object. But this new object has its own new reference counter.
You should notice that any two of these three identifier could not be used together.
-
nonatomic
means this object is not thread safe. So you must guess it. Yes! If you do not usenonatomic
and just use the default, the object will be thread safe and there will be scoped lock used internally.
-
转载请注明来自柳大的CSDN博客:Blog.CSDN.net/Poechant
-
分享到:
相关推荐
Objective-C是苹果公司用于iOS和OS X应用开发的编程语言,由于其与C语言的兼容性以及面向对象的特性,使其成为苹果早期开发者的首选语言。 书中提到了“Developer’s Library”,这是一套专门为编程专业人士设计的...
通过上述分析,可以看出《Programming in Objective-C (4th Edition)》是一本为程序员准备的实用教程,它不仅覆盖了Objective-C语言的基础知识,还结合了Xcode开发工具和iOS 5平台的开发环境,适合初学者和希望提升...
《Programming in Objective-C》是一本专注于Objective-C编程语言的书籍,由Stephen G. Kochan撰写,是开发者图书馆系列的一部分。这本书特别适合那些对iOS开发感兴趣的人阅读。在书中,首先介绍了Objective-C的基础...
综上所述,这本《Programming in Objective-C, 6th Edition》是一本针对苹果操作系统的应用开发者的权威教材,旨在提供Objective-C语言的系统性学习和应用指导。它着重强调了Objective-C编程技能的学习,为开发者...
MATLAB for Photomechanics- A Primer.zip.003
标题:“MATLAB for Photomechanics - A Primer.pdf” 明确指出了本书的主要内容是关于如何运用MATLAB软件来处理光力学问题。这是一本入门级书籍,旨在帮助读者了解并掌握如何使用MATLAB进行光学领域的散斑图像分析...
A Primer on Memory Consistency and Cache Coherence,主要介绍了Memory同一性和cache一致性的定义以及相关模型和协议。例如SC模型,TSO模型,松散序模型和cache一致性的两种协议:snoopy协议和目录一致性协议。...
《Programming in Objective-C (6th Edition)》是由Stephen G. Kochan编写的,这是一本关于Objective-C编程语言的教科书,该书是Developer’s Library系列的一部分。Developer’s Library系列的书籍旨在为从事日常...
总之,“Introduction to Wavelets and Wavelet Transforms -- A Primer”这本书结合了理论与实践,通过Matlab代码为初学者提供了一个全面了解和掌握小波变换的入口。通过深入学习和实践,读者将能够运用小波分析...
2. **系数导出**:根据这些频率点上的结果,推导出子载波级均衡器的系数。 3. **性能评估**:对所提出的方案进行误码率性能评估,并与SIMO/MIMO OFDM均衡器进行比较。 #### 五、信道均衡器的性能评估 通过对不同...
Data Mining: A Tutorial-Based Primer, Second Edition (Chapman & Hall/CRC Data Mining and Knowledge Discovery Series) by Richard J. Roiger 2016 | ISBN: 1498763979 | English | 529 pages | True PDF | 32 ...
2. **架构设计**:选择合适的架构模式,如客户端-服务器(C/S)、微服务、事件驱动等。 3. **数据存储**:考虑数据库的选择,如关系型数据库、NoSQL、键值存储等。 4. **负载均衡**:确保流量均匀分配,提高系统的...
### OWL2 Web Ontology Language Primer #### 概述 OWL2 Web Ontology Language(简称OWL2)是一种专为语义网设计的本体语言,它具有明确的形式化定义意义。该语言允许用户定义类、属性、个体以及数据值,并且这些...
MATLAB for Photomechanics- A Primer.zip.002