From C++ to objective-C
杜致远
description C++ Objective-C
函数 int foo(int a, char b){} -(int) foo : (int) a : (char) b {}
函数 static int foo(int a, char b) { } + (int) foo : (int) a : (char) b {}
参数命名 - (void) foo2 val1 : (int) a;
函数调用 [obj foo2 val1 : 5];
指针定义 AAA* ptr = …; AAA* ptr = …;
指针对象调用函数 ptr->foo(5,3) [ptr foo:5:3]
虚类 class foo { virtual void somefunction ( ) = 0; }; @protocol foo - (void) somefunction;
继承 class c1 : public NSObject, public foo { void somefunction() {…} } @interface c1 : NSObject @ end @implementation c1 - (void) somefunction {…}
检查函数是否实现 if ([ptr respondsToSelector : @selector(::))
向下转型 foo* f = dynamic_cast<foo*>(ptr) [ptr isKindOfClass: [foo class]]
?符合协议
void void* ptr = … id ptr = …
指代自身的指针 this self
成员函数类外实现 void f1 :: foo() {…} @implementation f1 - (void) foo {…} @end
* ptr->AddRef() [ptr retain]
* ptr-Release() [ptr release]
  1. -表示常规方法,+表示静态方法
  2. 指针对象调用函数:当ptr为nil时,OC可以忽略这次调用(C++可能会抛出异常)
  3. OC中的Protocol = C++中的Abstract class,在OC中function不一定要实现
  4. 在C++中接口如果有未实现的函数,则无法编译通过,但在OC中可以编译,如果调用了这样的函数则会抛出异常,所以需要对某个函数是否实现进行检查
  5. 向下转型??
  6. SEL @selector ??
  7. OC中的类的写法
1
2
3
4
5
6
7
8
9
10
11
12
// Objective C
@class f2; // forward declaration
@interface f1 : NSOBject // Objective-C supports only public and single inheritance
{
int test; // default = protected
@public
int a;
int b;
f2* f;
}
- (void) foo;
@end
  1. ?? OC中的多线程
  2. automatic reference counting

喵,看不下去了

本来是想找一个快速入门的方法,然后发现这篇文章对我来说还是太晦涩了,有时候知识是融会贯通的,就想学英文,在一页出现5个生词我们还乐于去推测和学习,而且能够根据上下文揣摩到许多知识,学习效果不错,一页大半都是生词的话,学习热情被伤害了。。。
还是不求速度了,似乎并不是速成型选手,踏实一点看长教程吧。QAQ
希望自己学的更明白了能好好再写一遍这篇文章。