Git Product home page Git Product logo

raexpendable's Introduction

RAExpendable

NSObject subclass with dynamically added implementations for custom selectors.

What’s Inside

There’s RAExpendable, you use it when you’re dealing with an inline object that needs delegation to work, and would not wish to create separate classes for them, or when you’re dealing with multiple inline objects which are all chatty, and require delegation to cover the whole gamut of their behavior.

Here’s a snippet from its test:

RAExpendable *expendable = [RAExpendable new];
STAssertThrows([expendable performSelector:@selector(foo)], @"object should not answer to selector yet");

[expendable addMethodForSelector:@selector(foo) types:"v@:" block:^{
	NSLog(@"Foo");
}];
STAssertNoThrow([expendable performSelector:@selector(foo)], @"object should answer to selector");

Drop the Xcode project into your project, then link against it as a static library.

Licensing

This project is in the public domain. You can use it and embed it in whatever application you sell, and you can use it for evil. However, it is appreciated if you provide attribution, by linking to the project page (https://github.com/evadne/RAExpendable) from your application.

Credits

raexpendable's People

Contributors

evadne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

raexpendable's Issues

Blocks with arguments do not work the way you think

The Readme does not completely document how to deal with methods that take arguments. The obvious way does not work:

RAExpendable *expendable = [RAExpendable new]; [expendable addMethodForSelector:@selector(foo:) types:"v@:@" block:^(id bar) { NSLog(@"%@", bar); }]; [expendable performSelector:@selector(foo:) withObject:@"hello"];
logs
<RAExpendable-EC293482-371E-4A0D-8A84-0080889B5703: 0xc838670>

The right way is

RAExpendable *expendable = [RAExpendable new]; [expendable addMethodForSelector:@selector(foo:) types:"v@:@" block:^(RAExpendable *expendable, id bar) { NSLog(@"%@", bar); }]; [expendable performSelector:@selector(foo:) withObject:@"hello"];

and similarly, the example in the Readme should be:

RAExpendable *expendable = [RAExpendable new]; [expendable addMethodForSelector:@selector(foo) types:"v@:" block:^(RAExpendable *expendable) { NSLog(@"Foo"); }]; [expendable performSelector:@selector(foo)];

In other words, the first argument of the block needs always to be the RAExpendable.

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.