Articles in the obj-c category

  1. "[Objective-C] Basic Concepts"

    Property

    Use weak property to avoid strong reference cycle

    • Typical senario: delegate
    +---------------------------------------------------------------------+
    | NSTableView:                       Delegate Object:                 |
    |                          strong                                     |
    |                        --------->                                   |
    | @property id delegate;            @property NSTableView *tableview; |
    |                        <---------                                   |
    |                          strong                                     |
    +---------------------------------------------------------------------+
    
    • Solution: declare 'delegate' as weak property
    +----------------------------------------------------------------------------+
    | NSTableView:                              Delegate Object:                 |
    |                                  weak                                      |
    |                               --------->                                   |
    | @property (weak) id delegate;            @property NSTableView *tableview; |
    |                               <---------                                   |
    |                                 strong                                     |
    +----------------------------------------------------------------------------+
    

    Use object cache to keep weak object alive

    • In …