Objective-C的.h与.m文件中公有和私有函数的声明和定义方式[学习笔记]
2013-09-11 13:23
603 查看
在.h文件中,
@interface与@end之间声明的是公有的方法
在.m文件中,
@interface与@end之间声明的是私有的方法(注意:与在.h中声明不同,类名要有"()",后面不用写继承的基类);
@implementation与@end之间定义公有或私有的方法
例如:
Spaceship.h
Spaceship.m
@interface与@end之间声明的是公有的方法
在.m文件中,
@interface与@end之间声明的是私有的方法(注意:与在.h中声明不同,类名要有"()",后面不用写继承的基类);
@implementation与@end之间定义公有或私有的方法
例如:
Spaceship.h
#import "Vehicle.h" #import "Planet.h" @interface Spacship : Vehicle //declaration of public methods //.h文件中,@interface与@end之间声明的是公有的方法 @property (nonatomic) double topSpeed; - (void) orbitPlanet:(Planet *)aPlanet atAltitude:(double)km; @end
Spaceship.m
#import "Spaceship.h" @interface Spaceship() //declaration of private methods (as needed) //.m文件中,@interface与@end之间声明的是私有的方法(注意:与在.h中声明不同,类名要有"()",后面不用写继承的基类) @property (nontoxic, strong) Warmhole *nearestWormhole; @end @implementation Spaceship //implementation of public and private methods //@implementation与@end之间定义公有或私有的方法 @synthesize topSpeed=_topSpeed; @synthesize nearestWormhole=_nearestWormhole; - (void) setTopSpeed:(double)speed { _topSpeed=speed; } - (double) topSpeed { return _topSpeed; } - (void) orbitPlanet:(Planet *)aPlanet atAltitude:(double)km { //put the code to orbit a planet here }
相关文章推荐
- 学习笔记之C++为什么将函数声明或者类的定义放在.h文件中,而将其实现放在原文件中
- Objective-C学习笔记(十三)——函数的声明与调用
- [原创]java WEB学习笔记31:会话与状态管理 session机制 概述(定义,session机制,session的声明周期,保存session的方式,Session的创建与删除)
- C语言学习笔记:13_变量和函数的声明与定义
- Objective-C学习笔记(十八)——对象方法和类方法的声明,定义及调用
- Javascript学习笔记:3种定义函数的方式
- c++学习笔记之基础---类内声明函数后在类外定义的一种方法
- Objective-C学习笔记(十八)——对象方法和类方法的声明,定义及调用
- Objective-C 学习笔记(二) 类声明,定义,实例,初始化
- Objective-C 学习笔记(二) 类声明,定义,实例,初始化
- Scala学习笔记(四) - 变量,常量,函数及类的定义
- Objective-c学习日总结之与C的区别及类与对象的定义,类的声明及调用方法
- php学习笔记 定义常量,包含文件,判断常量是否存在
- Scala学习笔记05【Scala函数定义、流程控制、异常入门】
- 第二章、Objective-c 语法,类/属性/函数(iOS学习笔记,从零开始。)
- Linux学习之库函数方式文件编程
- 黑马程序员_学习笔记8用类加载器的方式管理资源和配置文件及类加载器的总结
- php学习笔记之---[函数声明(一)]
- JavaScript学习笔记3-JavaScript定义对象的四种方式
- Spring4学习笔记-Spring4整合Struts2(基于配置文件的方式)