Non-retaining array for delegates

后端 未结 10 1419
感动是毒
感动是毒 2020-11-29 18:41

In a Cocoa Touch project, I need a specific class to have not only a single delegate object, but many of them.

It looks like I should create an NSArray for these del

10条回答
  •  星月不相逢
    2020-11-29 19:09

    I'd suggest to not-fight-the-framework and use NSPointerArray with the NSPointerFunctionsWeakMemory NSPointerFunctionOption like this:

    NSPointerArray *weakReferencingArray = [NSPointerArray pointerArrayWithOptions:NSPointerFunctionsWeakMemory];
    
    // NSPointerFunctionsWeakMemory - Uses weak read and write barriers 
    // appropriate for ARC or GC. Using NSPointerFunctionsWeakMemory 
    // object references will turn to NULL on last release.
    

    Served me well in scenarios, where I had to design a delegates array, which auto-NULL's references.

提交回复
热议问题