微信登录

功能 - 类的定义与实现 - .h -> .m

@ interface .h定义文件

  1. @interface MyClass : NSObject {
  2. int memberVar1; // 实体变量
  3. id memberVar2;
  4. }
  5. + (return_type)class_method; // 类方法
  6. - (return_type)instance_method1; // 实例方法
  7. - (return_type)instance_method2:(int)p1;
  8. - (return_type)instance_method3:(int)p1 andPar:(int)p2;
  9. @end

|
|
V

@ implementation .m实现文件

  1. @implementation MyClass {
  2. int memberVar3; // 私有实体变量
  3. }
  4. - (return_type)instance_method1 {
  5. ....
  6. }
  7. - (return_type)instance_method2:(int)p1 {
  8. ....
  9. }
  10. - (return_type)instance_method3:(int)p1 andPar:(int)p2 {
  11. ....
  12. }
  13. @end

import导入文件

  1. #import <文件目录/文件名>

@ implementation @ interface 后有@ end结束

+ 静态 - 非静态

实例化创建对象 + 使用方法

  1. Car *car = [Car new];
  2. [类 方法:@"标题" : @"目录"];
  3. [car go:@"车类" : @"开车"];
功能 - 类的定义与实现 - .h -&gt; .m