Giter VIP home page Giter VIP logo

arnswizzblocks's Introduction

ARNSwizzBlocks

Build Status

I aimed at the implementation of ReactiveCocoa Signal Message Forwarding.

Features

Features of ARNSwizzBlocks is the following

  • Method Swizzling of Instance Method.

  • Method Swizzling Influence range is Only Instance Object.

Respect

It was inspired by the following products.

Requirements

Requires iOS 7.0 or later, and uses ARC.

How To Use

Method Swizzle

@property (nonatomic, weak) IBOutlet UITableView *tableView;

...

- (void)viewDidLoad
{
    [super viewDidLoad];
	
    [self arn_swizzRespondsToSelector:@selector(tableView:cellForRowAtIndexPath:) fromProtocol:@protocol(UITableViewDataSource) usingBlock:^UITableViewCell *(id obj, UITableView *tableView, NSIndexPath *indexPath) {
    	// Call!!
        static NSString *cellIdentifier = @"cellIdentifier";
        UITableViewCell *cell           = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        
        if (!cell) {
            cell                     = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
            cell.selectionStyle      = UITableViewCellSelectionStyleNone;
        }
        
        cell.textLabel.text = @"Swizz!";
        
        return cell;
    }];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	// Not Call
    return nil;
}
- (IBAction)tapSwizzButton:(id)sender
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"test" message:@"Swizz" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
    [self arn_swizzRespondsToSelector:@selector(alertView:clickedButtonAtIndex:) fromProtocol:@protocol(UIAlertViewDelegate) usingBlock:^(id obj, UIAlertView *alertView, NSInteger buttonIndex) {
    	// Call!!
    }];
    [alertView show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    // Not Call
}

Licensing

The source code is distributed under the nonviral MIT License.

It's the simplest most permissive license available.

Japanese Note

ReactiveCocoaのMessage Forwarding機構を参考にして、

既存インスタンスメソッドの差し替えを行うカテゴリを作りました。

インスタンスメソッドの差し替えは、差し替えたインスタンスのみにか反映されないようにしています。

ReactiveCocoaの実装に関しては、以下の解説を参考にさせていただきました。

http://qiita.com/ikesyo/items/9c6b00e2b00d8f5e3e11

検証が甘いので、ご使用はお勧め出来ません。。

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.