当前位置:首页 > 编程开发

xcode objective-c categroy 与extersion

webgou14年前 (2012-08-14)编程开发256
1,分类categroy 增加类方法一种手断,不能有成员变量。这个跟c++与java抽象类与接口还是有些不一样。类函数分类。 2.扩展extersion 匿名的categroy,实现可以有成员变量。 下面是实现的例子: [CODE_LITE] // // Category.h // objc // // Created by sunkey on 12-8-13. // Copyright (c) 2012年 sunkey. All rights reserved. // #import @interface Computer : NSObject { int i; } -(void)PCName; //Category is implementing a method which will also be implemented by its primary class //-(void)Width; @end //extersion @interface Computer() { int iValue; } -(void)SetIVaule:(int)newValue; @end @interface Computer (NoeBook) { //Ivars may not be placed in categories //int j; } -(void)NoteName; -(void)Width; -(void)Height; +(void)NSCPU; @end // // Category.m // objc // // Created by sunkey on 12-8-13. // Copyright (c) 2012年 sunkey. All rights reserved. // #import "Category.h" @implementation Computer -(void)PCName { i = -1; NSLog(@"pc %d\n",i); [self NoteName]; } /* -(void)Width { i = 200; NSLog(@"width %d\n",i); } */ -(void)SetIVaule:(int)newValue { iValue = newValue; } @end @implementation Computer (NoeBook) -(void)NoteName { //[self PCName]; i = 1; NSLog(@"note %d\n",i); } -(void)Width { i = 100; NSLog(@"width %d\n",i); } -(void)Height { NSLog(@"height %d\n",i); } +(void)NSCPU { NSLog(@"intel \n"); } @end [/CODE_LITE] 扩展:https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocCategories.html

扫描二维码推送至手机访问。

版权声明:本文由知了博客发布,如需转载请注明出处。

本文链接:https://www.webgou.info/?id=520

标签: iosiphonexcode
分享给朋友:

“xcode objective-c categroy 与extersion” 的相关文章

使用Nginx实现根据 IP 匹配指定 URL

 最近的一个项目,需要特定的IP访问某专题页面的时候跳转到网站首页,思考了下,直接使用NGINX实现,分享给大家。业务需求...…

对话框条的制作CDialogBar

1.创建对话框资源:在对话框资源编辑器内生成一个属性必须设置为....…

iOS vs Android

iOS vs Android…

devenv.exe的命令行参数

devenv.exe的命令行参数…

中国iOS开发者出走海外

7月6日,知名移动数据监测机构App Annie在移动互联网创新大会上公布的这组数据揭开了中国移动互联网产业的现实与无奈。 整个iOS市场中,中国区APP下载量排名全球第二,但收入只排到全球第八,中国平均每下载量收入仅有0.03美元,是美国用户0.28美元的十分之一,甚至只有越南的一半。 在iO…

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。