1.合成存取器方法

@property   成员变量

@synthesize 成员变量 

可以让编译器自动合成 设置和获取函数的方法,不用手动生成set成员变量,Get成员变量

 

@interface Complex : NSObject

{

    int iReal,iImag;

}

@property  int iReal, iImag;  //合成存取器方法,第一部:@property标识属性

-(void)print;

@end

 

@implementation Complex

@synthesize iReal, iImag;//合成存取器方法,第二步:告诉编译器自动生成存取器

-(void) print

{

    NSLog(@"iReal = %i, iImag = %i", iReal, iImag);

}

@end

 

2.调用方法和成员

[myComplex  print];

也可以  myComplex.print

[myComplex iReal];

也可以  myComplex.iReal

 

3.多个参数的方法

1个方法同时设置实部和虚部

-(void)SetReal : (int) n SetImag:(int)d

也可以省略参数名

-(void)SetComplex:(int)n:(int)d

 

4.指向实例本身,self相当于C++ this

相关文章:

  • 2022-01-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-01
  • 2022-01-24
  • 2021-08-17
猜你喜欢
  • 2021-09-01
  • 2021-08-25
  • 2022-01-15
  • 2021-08-19
  • 2021-10-09
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案