//
// CCNSArray.h
// CCFC
//
//
#import <Foundation/Foundation.h>
@interface NSArray(cc)
// 判断一个对象指针(不是对象的值)是否在数组中存在
- (BOOL)isPointerExistsInArray:(id)element;
// print the retainCount of each element
- (void)printRetainCountOfEach;
// deep copy, you should release the return value outside // not ok
- (NSMutableArray *)deepCopy;
// print all the element's address
- (void)printAllElementAddr;
@end
@interface NSMutableArray(cc)
// add a null element
- (void)addNull;
@end
//
// CCNSArray.m
// CCFC
//
#import "CCNSArray.h"
#import "CCNSObject.h"
@implementation NSArray(cc)
// 判断一个对象指针(不是对象的值)是否在数组中存在
- (BOOL)isPointerExistsInArray:(id)element
{
for(id temp in self)
{
if(temp == element)
{
return TRUE;
}
}
return FALSE;
}
// print the retainCount of each element
- (void)printRetainCountOfEach
{
for(id obj in self)
{
[obj showRetainCount];
}
}
// deep copy, you should release the return value outside // not ok
- (NSMutableArray *)deepCopy
{
return (NSMutableArray *)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (CFPropertyListRef)self, kCFPropertyListMutableContainers);
}
// print all the element's address
- (void)printAllElementAddr
{
for(id element in self)
NSLog(@"element addr is %p", (void *)element);
}
@end
@implementation NSMutableArray(cc)
// add a null element
- (void)addNull
{
[self addObject:[NSNull null]];
}
@end
微风不燥,阳光正好,你就像风一样经过这里,愿你停留的片刻温暖舒心。
我是程序员小迷(致力于C、C++、Java、Kotlin、Android、Shell、JavaScript、TypeScript、Python等编程技术的技巧经验分享),若作品对您有帮助,请关注、分享、点赞、收藏、在看、喜欢,您的支持是我们为您提供帮助的最大动力。
欢迎关注。助您在编程路上越走越好!