<commit_before># TPWeakProxy

An NSProxy object for turning strong references into weak references.

## Usage

    // Create a weak proxy to the object which you would like to be weakly referenced.
    // For example, self.

    TPWeakProxy *proxy = [[TPWeakProxy alloc] initWithObject:self];
    
    // Now, you can use proxy anywhere you'd normally use self,
    // except that self will have a weak reference to it where you use the proxy.
    
    // As an example, NSTimer maintains a strong reference to its target. Sometimes
    // this isn't what you want.

    NSTimer *myWeakRefTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
                                                               target:proxy
                                                             selector:@selector(myWeakRefTimerFired:)
                                                             userInfo:nil
                                                              repeats:NO];
                                                              
## Installation

Easiest way: use Cocoapods. Otherwise, copy the .h and .m into your project.

    $ edit Podfile
    platform :ios, '6.1'
    pod 'TPWeakProxy', '~> 1.0.0'
    
    $ pod install
    
    $ open App.xcworkspace
    
## Motivation

TPWeakProxy solves the problem of reference loops. This can happen when an object you instantiate keeps a strong reference to the object by which it was instantiated - making it impossible for the first object to die while the second object continues to exist.

An example of where this can be a problem is with the fairly common pattern in iOS development of using NSTimers. 

For example, let's say you have a UIViewController which wants to trigger a refresh event. The naive approach:

    @interface

    @property (strong, non-atomic) NSTimer *myTimer;
    <commit_msg>Clean up language in Motivation section intro.<commit_after># TPWeakProxy

An NSProxy object for turning strong references into weak references.

## Usage

    // Create a weak proxy to the object which you would like to be weakly referenced.
    // For example, self.

    TPWeakProxy *proxy = [[TPWeakProxy alloc] initWithObject:self];
    
    // Now, you can use proxy anywhere you'd normally use self,
    // except that self will have a weak reference to it where you use the proxy.
    
    // As an example, NSTimer maintains a strong reference to its target. Sometimes
    // this isn't what you want.

    NSTimer *myWeakRefTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
                                                               target:proxy
                                                             selector:@selector(myWeakRefTimerFired:)
                                                             userInfo:nil
                                                              repeats:NO];
                                                              
## Installation

Easiest way: use Cocoapods. Otherwise, copy the .h and .m into your project.

    $ edit Podfile
    platform :ios, '6.1'
    pod 'TPWeakProxy', '~> 1.0.0'
    
    $ pod install
    
    $ open App.xcworkspace
    
## Motivation

TPWeakProxy solves the problem of object reference loops in Objective C. Reference loops can occur when an instantiated object keeps a strong reference to the object by which it was instantiated - making it impossible for the first object to be deallocated while the second object continues to exist.

An example of where this can be a problem is with the fairly common pattern in iOS development of using NSTimers. 

For example, let's say you have a UIViewController which wants to trigger a refresh event. The naive approach:

    @interface

    @property (strong, non-atomic) NSTimer *myTimer;
    
{'fraction_non_alphanumeric': 0.05157365776249669, 'fraction_numerical': 0.0037027241470510446, 'mean_word_length': 1.8287210172026926, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '845338', 'n_tokens_mistral': 911, 'n_tokens_neox': 838, 'n_words': 413}