1.
OC [[UIView alloc]initWithXXX:xxx]
Swift UIView(XXX: )
UIView() :类名()与 alloc / init 等价
2.
OC [UIColor redColor]
Swift UIColor.red && Color Literal
3. 访问当前对象的属性,可以不使用self.
建议:
都不用,在编译器提示的时候,再添加,会对语境有更好的体会
原因:
闭包(类似于OC block),需要使用self.
4. 没有’;’
Swift默认不需要
5. 枚举类型
OC UIButtonTypeContactAdd
Swift '.'contactAdd
6. 监听方法
OC @selector
Swift #selector 如果有参数,不需要:
7. 调试
OC NSLog
Swift print
-没有时间
-效率比NSLog高
OC __FUNCTION__
Swift #function
代码:
1 | class ViewController: UIViewController { |