iOS开发—在@interface,@implementation和@property中变量的定义
来源:互联网 发布:上海游泳教练知乎 编辑:程序博客网 时间:2024/05/18 00:59
http://www.chirenhua.com/ios%E5%BC%80%E5%8F%91-%E5%9C%A8interfaceimplementation%E5%92%8Cproperty%E4%B8%AD%E5%8F%98%E9%87%8F%E7%9A%84%E5%AE%9A%E4%B9%89/?utm_source=tuicool&utm_medium=referral
一直搞不懂在OC中变量在@interface和@implementation中有什么区别,定义@property又有什么不同,查了很多资料,总结如下:
//ViewController.h@interface ViewController : UIViewController { NSInteger a;}@property (nonatomic,assign) NSInteger b;@end//ViewController.m@interface ProductsViewController () { NSInteger c;}@property (nonatomic,assign) NSInteger d;@end
a,b,c,d这四个变量有什么不同?
a是成员变量,相当于java中的protected,可以被子类继承。
b相当于java中的public,既可以被子类继承,也可以被外部访问。
c和d个人理解都是私有变量,相当于java中的private,不可以被子类调用,也不可以外部访问。
b 和 d 可以用 self.来访问, a和c不能。
a和c基本上很少用,一般都用b和d,如果需要对外开放的属性的就放在b,不需要的话直接在d位置定义。
a和c我觉的应该是为了兼容早期版本的写法,为了让你自己定义属性对应的内部变量,但是在arc之后的版本中,你只要定义一个属相,xcode会自动帮你定义一个以下划线打头的和属性同名的内部变量,所以你不需要另外再定义了.
0 0
- iOS开发—在@interface,@implementation和@property中变量的定义
- iOS开发—在@interface,@implementation和@property中变量的定义
- iOS开发中@interface 和 @implementation区别, @property 和@synthesize区别
- ios中的成员变量定义在@interface 和@implementation 中的区别是什么?
- 实例变量 定义在 @interface 和 @implementation 有何区别?
- 定义变量的位置 @interface VS @implementation
- @interface中定义变量与@property的区别
- IOS OC声明变量在@interface括号中与使用@property的区别
- IOS OC声明变量在@interface括号中与使用@property的区别
- IOS OC声明变量在@interface括号中与使用@property的区别
- IOS OC声明变量在@interface括号中与使用@property的区别
- IOS OC声明变量在@interface括号中与使用@property的区别
- IOS OC声明变量在@interface括号中与使用@property的区别
- IOS OC声明变量在@interface括号中与使用@property的区别
- IOS OC声明变量在@interface括号中与使用@property的区别
- IOS OC声明变量在@interface括号中与使用@property的区别
- iOS OC声明变量在@interface括号中与使用@property的区别
- iOS声明变量在@interface括号中与使用@property的区别
- mybatis获取xml文件中property对应的column
- .gitignore 的编写
- Android读写文件 获取文件并读取写入数据
- Android Dev Intro - Introducing GLSurfaceView
- IOS开发-VFL语言
- iOS开发—在@interface,@implementation和@property中变量的定义
- android5.0 如何开启wif热点
- Flume-Kafka-Logstash-ElasticSearch-Kibana流程说明
- 属性声明在@implementation里与extension里的区别
- objective-c - 基础篇 - UIWebView
- ios 关于UIWebView控件的使用
- UIMenuController使用
- jquery绑定自定义事件
- 【PHP PDO】纯PHP(不使用框架)下 Mysql PDO 使用方法小记