Code Monkey home page Code Monkey logo

jgweaktarget's Introduction

JGWeakTarget

A proxy object used to weak reference the target in a target/selector callback. To use, initialize an instance of JGWeakTarger with the desired target and selector. Then, use the weakTarget and weakSelector property when creating a target/selector callback. JGWeakTarget will maintain a weak reference to the target and relay the recieved callbacks to the selector.

Example

The following example creates a weak reference to self using JGWeakTarget. After creating an instance of JGWeakTarget, the weakTarget and weakSelector properties are used as the target and the selector for the NSTimer. This creates a normally functioning target/selector callback with the difference in that the NSTimer does not hold a strong reference to self. Thus, the timer will not prevent self from being deallocated. Notice that this also implies that, upon deallocation of the class with the weak reference, the timer must be invalidated.

JGWeakTarget *weakSelf = [JGWeakTarget weakTargetWithTarget:self selector:@selector(timerFired:)];
[NSTimer scheduledTimerWithTimeInterval:10 target:weakSelf.weakTarget selector:weakSelf.weakSelector userInfo:nil repeats:YES];

JGWeakTarget can be used with any classes that take target/selector parameters, such as CADisplayLayer and NSTimer. In addition, selectors with or without sender arguments can be used.

jgweaktarget's People

Contributors

jadengeller avatar

Stargazers

depthlove avatar  avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.