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

xcode objective-c categroy 与extersion

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

mysql 5.0存储过程学习总结

一.创建存储过程 1.基本语法:create procedure sp_name() begin ......... end 2.参数传递 二.调用存储过程 1.基本法:call sp_name() 注意:存储过程名称后面必须加括号,哪怕该存储过程没有参数传递 三.删除存储过程...…

DirextX 学习

正研究MPC-HP开源项目的源码,里面用到的很重要的DirectX技术,由于初识DirectX,所以一切得从零开始...…

Windows CE下流驱动的动态加载

Windows CE下流驱动的动态加载…

线程同步

效率      you should try to use nonshared data first and then use volatile reads, volatile writes, interlocked APIs, SRWL…

devenv.exe的命令行参数

devenv.exe的命令行参数…

35个强大的UI设计教程

下面是35个非常不错的UI设计的的教程及效果图,非常不错哦。不但教你如何做一些特效,同样教你如何做UI布局和界面设计。当然,他们风格迥异,也基本上都是Web页面上的。都非常不错。希望你喜欢。(点击下面的图片可以打开相关的教程) Old Paper Layout   Professiona…

发表评论

访客

看不清,换一张

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