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

xcode objective-c categroy 与extersion

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

xmlbean使用

过了几个月突然想到使用xmlbean,一到下午什么都记不起来,翻了老半天,看了下批命令才有点印像。之前打算深入研究一下xmlbean都吾有时间,现在把在公司用到的批命令记下来:1.inst2xsd -design ss -simple-content-types smart  f:\xml…

CentOS7安装Docker与使用篇

 一、在CentOS7上安装docker篇1. 查看系统版本: ...…

使用虚列表和自画实现文件夹的缩略图显示

预备性阅读在阅读本文之前,建议先对列表视图控件和系统外壳有一个基本的了解。建议阅读以下SDK文章 Shell FAQ List-View Controls Overview...…

Android屏幕元素相关概念详解

在Android手机操作系统中有很多比较重要的知识点需要我们在学习的过程中详细了解以方便我们将来的应用。比如Android屏幕元素等等。在这里就会为大家详细介绍一…

VS2005 C++ 项目怎样添加“依赖”、“库目录”和“包含目录”

1. 添加编译所需要(依赖)的 lib 文件…

Java Dom解析XML

˂1、XML文件persons.xml内容如下:<?xml version="1.0" encoding="UTF-8"?><persons>  <person><name>jak</name&g…

发表评论

访客

看不清,换一张

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