成员变量语法
定义的是外部可见的属性
#import <Foundation/Foundation.h> @interface People : NSObject @property (nonatomic,copy) NSString * run; @property (nonatomic,copy) NSString * sing; @end @implementation People @synthesize run;//可写可不写 @synthesize sing;//可写可不写 @end 可写的话 使用的是 run 不写的话 使用的是 _run
@interface Student : People @end
#import <Foundation/Foundation.h> @interface People : NSObject @property (nonatomic,copy) NSString * run; @property (nonatomic,copy) NSString * sing; @end 在h文件中申明成员变量 run 可以供子类调用和赋值
#import "People.h" @interface People() @property (nonatomic,copy) NSString * run; @property (nonatomic,copy) NSString * sing; @end @implementation People @end
成员变量定义在m文件 run 属性不能供子类调用赋值 就会提示:Property ‘sing‘ not found on object of type ‘Student *‘
时间: 2024-10-29 00:49:53