关于分类(category)和类的扩展(extensions)的验证
2012-11-16 12:30
288 查看
关于关于分类(category)和类的扩展(extensions)的验证:
分类的一大特性就是可以 :将类的实现分散到多个不同文件或多个不同框架中。分类允许分开编译,也就是说,同一个类也可以进行多人的分工合作;
那如何才能实现分工合作呢?下面做一下验证:例子来自《iOS5开发基础教程》第8章(也就是《iOS5开发基础教程》最新版的“08
- Sections2”下载地址:http://vdisk.weibo.com/s/hBHg6)
对该实例就行如下修改:
Ctrl+N新建:
表视图运行正常,并且输出5,
中间的例子就体现了分类与扩展的思想,用到了两种分类的方法:.m文件声明与实现(extension),也就是sum:方法;以及单独新建.h声明方法,将category方法分散到不同的.m文件(此实例中只用到一个.m文件)调用实现。
实例完整工程下载地址:Hi,推荐文件给你 "tableViewTest.zip"
http://vdisk.weibo.com/s/if_0R
分类的一大特性就是可以 :将类的实现分散到多个不同文件或多个不同框架中。分类允许分开编译,也就是说,同一个类也可以进行多人的分工合作;
那如何才能实现分工合作呢?下面做一下验证:例子来自《iOS5开发基础教程》第8章(也就是《iOS5开发基础教程》最新版的“08
- Sections2”下载地址:http://vdisk.weibo.com/s/hBHg6)
对该实例就行如下修改:
Ctrl+N新建:
// NSDictionary-MutableDeepCopy.h #import <Foundation/Foundation.h> @interface NSDictionary(MutableDeepCopy) -(NSMutableDictionary *)mutableDeepCopy:(id)dic; @end
// BIDTableViewViewController.m #import "BIDTableViewViewController.h" #import "NSDictionary-MutableDeepCopy.h" @interface BIDTableViewViewController () { NSInteger *abc; } -(NSInteger)sum:(NSInteger)number; @end @implementation BIDTableViewViewController @synthesize search; @synthesize table; @synthesize staticDictionary; @synthesize keyOfSearched; @synthesize namesOfSearched; //@synthesize namesOfSearched; - (NSMutableDictionary *)mutableDeepCopy:(id)dic { NSMutableDictionary *returnDict = [NSMutableDictionary dictionaryWithCapacity:[dic count]]; NSArray *keys = [dic allKeys]; for (id key in keys) { id oneValue = [dic valueForKey:key]; id oneCopy = nil; if ([oneValue respondsToSelector:@selector(mutableDeepCopy)]) oneCopy = [oneValue mutableDeepCopy:oneValue]; else if ([oneValue respondsToSelector:@selector(mutableCopy)]) oneCopy = [oneValue mutableCopy]; if (oneCopy == nil) oneCopy = [oneValue copy]; [returnDict setValue:oneCopy forKey:key]; } return returnDict; } -(NSInteger)sum:(NSInteger)number { return(number+5); }
表视图运行正常,并且输出5,
中间的例子就体现了分类与扩展的思想,用到了两种分类的方法:.m文件声明与实现(extension),也就是sum:方法;以及单独新建.h声明方法,将category方法分散到不同的.m文件(此实例中只用到一个.m文件)调用实现。
实例完整工程下载地址:Hi,推荐文件给你 "tableViewTest.zip"
http://vdisk.weibo.com/s/if_0R
相关文章推荐
- 关于分类(category)和类的扩展(extensions)的验证
- 关于分类(category)和类的扩展(extensions)
- 关于分类category与类扩展extension的区别
- Objective-C分类 (category)和扩展(Extension)
- Objective-C分类 (category)和扩展(Extension)
- ASP.NET MVC验证框架中关于属性标记的通用扩展方法
- 【IOS开发技术】 Objective-C分类 (category)和扩展(Extension)
- 深入浅出理解分类(category)和类扩展(extension)
- iOS开发之OC篇(12)—— Category(分类)、Extension(扩展)
- 黑马程序员_oc特有语法一:分类Category和类扩展
- 分类(category)和类扩展(extension)的关系
- ios 分类(category)和类扩展(extension)详解
- 关于ios object-c 类别-分类 category 的静态方法与私有变量,协议 protocol 
- Objective C 类别(Category)与类扩展(Extensions)
- (转)iOS分类和扩展(Categories和Extensions)
- 关于iOS 分类和扩展的区别
- 关于ios object-c 类别-分类 category 的静态方法与私有变量,协议 protocol&nbsp
- 关于ios object-c 类别-分类 category 的静态方法与私有变量,协议 protocol 
- ASP.NET MVC验证框架中关于属性标记的通用扩展方法
- 分类(category)和类扩展(extension)