iOS多播委托:XMPP中的GCDMultiCaseDelega

2016-07-06  本文已影响79人  Noonday

-(void)addDelegate:(id)delegate delegateQueue:(dispatch_queue_t)queue

{

if(!_managerDelegates) {

_managerDelegates= [[NSMutableArrayalloc]init];

}

if(!queue) {

queue =dispatch_get_main_queue();

}

dispatch_async(queue, ^{

if(![_managerDelegatescontainsObject:delegate])

{

NSValue*value = [NSValuevalueWithNonretainedObject:delegate];

[_managerDelegatesaddObject:value];

}

});

}

weak引用NSArray的实现

NSValue *value = [NSValue valueWithNonretainedObjectValue:myObj];

[array addObject:value];

and when you get the object:

value = [array objectAtIndex:x];

myObj = [value nonretainedObjectValue];

上一篇下一篇

猜你喜欢

热点阅读