Objective-C Primer(2)Private Methods and Class Properties
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?
//
// TestClass.m
// ObjectiveCTest
//
// Created by 超 鍾 on 12-5-6.
// Copyright (c) 2012年 http://blog.csdn.net/poechant. All rights reserved.
//
#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
-
相關文章
- 巧用 LLVM 特性: Objective-C Class Properties 解耦LVMObject解耦
- tc39 proposal: Classes private methods and getter/setters
- Objective-C Primer(1)Get started!Object
- Objective-C Class Ivar Layout 探索Object
- Objective-C Primer(3)Multiple arguments for one method, synthesize and dynamicObject
- Results of T2DFP and iT2DFP methods
- php class中public,private,protected,static的區別,以及例項PHP
- Objective-C 中的 Meta-class 是什麼?Object
- [譯]Objective-C中的meta-class是什麼。Object
- Objective-C 中的元類(meta class)是什麼?Object
- methods
- C# 3.0 feature 2--Extension methodsC#
- TypeError: Cannot read private member xxx from an object whose class did not declare itErrorObject
- Objective-C筆記-2Object筆記
- oracle 11gR2 如何修改 private ipOracle
- Struts2的properties配置檔案詳解
- There are 5 methods of index lookupIndex
- 神經病院Objective-C Runtime入院第一天—isa和ClassObject
- immy框架入門系列(2)——class框架
- 【譯】2. Java反射——Class物件Java反射物件
- Objective-C中get/set方法初探(2)Object
- css propertiesCSS
- Spring Boot 學習筆記(4):配置properties(2)Spring Boot筆記
- Stochastic Methods in Finance (1)ASTNaN
- Vue踩坑之旅——methodsVue
- bootstrap-select——Methodsboot
- C_Primer第2章 C語言概述C語言
- Database_PropertiesDatabase
- properties外掛
- 我的隨行筆記2 C++ Primer Plus筆記C++
- OpenRTMFP/Cumulus Primer(6)CumulusServer啟動流程分析(續2)Server
- OpenRTMFP/Cumulus Primer(18)AMF解析之AMFReader(續2)
- [譯] part 17: golang 方法methodsGolang
- 【Java 8實戰】Extension MethodsJava
- Python 的 Magic Methods 指南Python
- Statistical Computing and Empirical Methods
- 【Coursera GenAI with LLM】 Week 2 PEFT Class NotesAI
- Java 對 properties 檔案操作 (ResourceBundle 類和 Properties 類)Java