Object-c基础之三:面对对象开发@interface,@implementation
来源:互联网 发布:淘宝客工作室怎么运营 编辑:程序博客网 时间:2024/04/30 07:38
1.@interface
在java等语言编程中,创建类都是用class,但在object-c中,用@interface。
例子:
@interface circle :NSObject //定义名为circle的类,继承自NSObject
{
ShapeColorfillColor;//定义ShapeColor类型的实例变量 fillColor;
Shapebounds;//定义Shape类型的实例变量 bounds;
}
- (void)setFillColor:(ShapeColor)fillColor;//定义名为setFillColor的方法
2.@implementation
在object-c中,@interface定义放在.h文件中,而@implementation放在.m 文件,是.h文件的详细实现。
例子:
@implementation circle //结尾没有分号。
- (void)setFillColor:(ShapeColor)c
{
fillColor= c;//把参数c赋值给@interface中定义的fillColor;
}
3.实例化对象
为了使用我们已经定义的类,我们需要实例化对象,我们可以在我们创建的文件中的main()函数实例化:如下
int main(int argc, const char * argv[])
{
idshapes[3];//定义id类型数组
shapes[0]= [circle new];//实例化circle并赋值给shapes
[shapes[0]setFillColor:kRedColor];//调用方法进行赋值
}
今天就到这里,下次讲一下xcode4.x如何使用。
- Object-c基础之三:面对对象开发@interface,@implementation
- 【object-c基础】Object-c基础之三:面对对象开发@interface,@implementation
- 【object-c基础】@interface,@implementation
- C#——面对对象基础
- 面对对象4【抽象abstract】【接口interface】【多态】【instanceof关键字】【Object类】
- iOS开发之面对对象的三大特征小小总结
- Object-C 面向对象基础
- Object-C 基础之9 — 对象复制
- java/面对对象基础
- C#面对对象基础
- 面对对象基础概念
- 面对对象基础要点
- Objective-c中@interface、@implementation、@protocal
- Objective-c中@interface、@implementation、@protocal
- Objective-c中@interface、@implementation、@protocal、id
- Objective-c中@interface、@implementation、@protocal
- Objective-c中@interface、@implementation、@protocal
- IPhone开发之C基础(三)
- You AND Your Research
- 编译开源路由下iNode客户端njit8021xclient
- c# 小游戏 俄罗斯方块
- 使用VC++操作Excel文件
- 实现 Android 应用在开机时自启动
- Object-c基础之三:面对对象开发@interface,@implementation
- java线程的sleep(),wait(),notify(),yield();
- 从小型网站到超大规模网站的MySQL参考架构
- status 405请求错误
- Android 采用KSoap访问传入实体对象的webservice
- 数据挖掘、数据分析、人工智能及机器学习课程资源
- JavaScript游戏引擎列表
- 常用RGB颜色表
- tomcat在conf/Catalina/localhost目录下配置项目路径