ios开发(五):基本语法 Class
来源:互联网 发布:java程序设计哪本好 编辑:程序博客网 时间:2024/05/16 19:15
class分成两部分,一个是interface,一个是implementation
INTERFACE
1) 继承
@interface ClassName : ItsSuperclass
// Method and property declarations.
@end
2) 私有公有函数
+ alloc; // Class method, 没有返回数值,默认是id
- (void)setRadius:(float)aRadius; // instance method
3)属性(property)
@property (attributes) Type propertyName;
instance variables(大括号内的都是instance variable,这些变量都是私有的)
@interface ClassName : ItsSuperclass
{
// Instance variable declarations.
}
// Method and property declarations.
@end
4) @class Rectangle, Circle;
class的声明,声明之后就不需要再import文件了,这个和C++非常类似。
IMPLEMENTATION
1) @implementation ClassName
{// Instance variable declarations.
}
// Method definitions.
@end
2) operator (->)
@interface Sibling : NSObject
{
Sibling *twin;
int gender;
struct features *appearance;
}
- makeIdenticalTwin
{
if ( !twin ) {
twin = [[Sibling alloc] init];
twin->gender = gender; // 访问他本身就使用->
twin->appearance = appearance;
}
return twin;
}
3) scope
@interface Worker : NSObject
{
char *name;
@private
int age;
char *evaluation;
@protected
id job;
float wage;
@public
id boss;
}
SELF SUPER
[self setOrigin:someX :someY];
[super setOrigin:someX :someY];
- ios开发(五):基本语法 Class
- IOS开发-OC基本语法(1)
- PHP基本语法(五)
- iOS开发之OC语法基础(五)--字符串
- iOS 开发 -- Swift 语法篇 (五) 字符串
- ios开发(四):基本语法 Objects, Classes, and Messaging
- ios开发(六):基本语法 protocols Category extension
- ES6 —(Class 的基本语法)
- Class的基本语法
- IOS开发:swift 语言基本语法1
- iOS开发笔记- Swift基本语法
- iOS开发之Swift基本语法详解
- ios基本语法下篇()
- kotlin 基本语法(五)
- Android开发,Kotlin的了解与学习(五)-----基本语法之集合相关
- ios 基本语法介绍啦。(上篇)
- ios基本语法
- IOS:Swift基本语法
- 用JavaScript获取页面元素的位置
- Tomcat 启动超过45秒
- 第十三周——数组大折腾(二)
- 基于jibx解析xml中有很多field的xml
- 安卓发现的问题
- ios开发(五):基本语法 Class
- android开发小技巧
- svn代码回滚命令
- < Unity 3D专栏 >预设物,节省游戏资源才是王道
- php文件下载
- 查找最长子字符串
- VPS主机上建立WordPress网站后怎样实现邮件发送功能
- eclipse plugin site
- Java synchronized 详解