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

xcode objective-c categroy 与extersion

webgou14年前 (2012-08-14)编程开发220
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” 的相关文章

在Eclipse下安装C++插件CDT

按照eclipse的官方网站的要求,要下载如下的东东:1.eclipse(http://www.eclipse.org/downloads/index.php)…

汉字编码

一、汉字编码的种类     汉字编码中现在主要用到的有三类,包括GBK,GB2312和Big5。...…

C++面试之const、#define

问题1:const与#define相比有什么不同? C++可以用const定义常量,也可以用#define定义常量,但是前者比后者有更多的有点:…

AppStore 内购验证的方法

AppStore 内购验证的方法…

文件拖动

在VC中,我们可以不利用打开文件对话框来选择文件,从而对文件进行操作,我们也可以使用拖拽来实现这样的功能。具体如下:1.首先,把一个对话框或者窗体的扩展属性【接受文件】勾选上。2.我们对WM_DROPFILES消息进行处理。在这里我们使用到了一个API函数:DragQueryFile...…

Android 使用极光/友盟推送,APP进程在杀死后收不到推送的处理方法(转)

 为什么会存在这样的 问题,刚开始的时候我也搞不清楚,之前用极光的时候杀死程序后也会收到推送,但最近重新再去集成时就完全不好使了,这我就纳闷了,虽然Google在高版本上的Android上面不建议线程守护,所以将进程有关的Service都杀掉了,但旧版本还是有这个功能的啊 !真尼玛,后来猜…

发表评论

访客

看不清,换一张

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