Latest 0.4.0
Homepage https://github.com/JaonFanwt/WtDelegateProxy
License MIT
Platforms ios 8.0
Authors

CI Status
Version
License
Platform

将委托代理方法映射到block,当delegate调用对应的委托方法时,将会将它转换成调用block。

Example

映射方法如下:

- (void)selector:(SEL)selector block:(id)block;

使用方法示例:

- (void)testDemo {
    id block = ^() {
        NSLog(@"%s", __func__);
    };

    self.demoDelegate = (WtDelegateProxy<WtDemoProtocol> *)[[WtDelegateProxy alloc] initWithProtocol:@protocol(WtDemoProtocol)];
    [self.demoDelegate selector:@selector(demo) block:block];

    [self.demoDelegate demo];
}

以下示例是映射代理UITableViewDataSource中的2个委托方法:

@import WtDelegateProxy;

@interface WtDemoCellModel : NSObject
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subTitle;

@property (nonatomic, strong) WtDelegateProxy<UITableViewDataSource> *tableViewDataSource;
@end

@implementation WtDemoCellModel
- (instancetype)init {
    if (self = [super init]) {
        [self buildCellControl];
    }

    return self;
}

- (void)buildCellControl {
    __weak typeof(self) weakSelf = self;

    self.tableViewDataSource = (WtDelegateProxy<UITableViewDataSource> *)[[WtDelegateProxy alloc] initWithProtocol:@protocol(UITableViewDataSource)];

    [self.tableViewDataSource selector:@selector(tableView:cellForRowAtIndexPath:) block:^(UITableView *tableView, NSIndexPath *indexPath){
        __strong typeof(weakSelf) strongSelf = weakSelf;

        NSString *cellIdentifier = [NSString stringWithFormat:@"%@Identifier", [self class]];
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        }

        cell.textLabel.text = strongSelf.title;
        cell.detailTextLabel.text = strongSelf.subTitle;

        return cell;
    }];

    [self.tableViewDelegate selector:@selector(tableView:heightForRowAtIndexPath:) block:^(UITableView *tableView, NSIndexPath *indexPath){
        return 44.0;
    }];
}

Requirements

Installation

WtDelegateProxy is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "WtDelegateProxy"

Author

wtfan(long), [email protected]

License

WtDelegateProxy is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "WtDelegateProxy",
    "version": "0.4.0",
    "summary": "u5c06u4ee3u7406u65b9u6cd5u8f6cu4e3aBlocku65b9u6cd5.",
    "description": "TODO: Add long description of the pod here.",
    "homepage": "https://github.com/JaonFanwt/WtDelegateProxy",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "wtfan(long)": "[email protected]"
    },
    "source": {
        "git": "https://github.com/JaonFanwt/WtDelegateProxy.git",
        "tag": "0.4.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "WtDelegateProxy/Classes/**/*",
    "subspecs": [
        {
            "name": "Extensions",
            "ios": {
                "source_files": "Extensions/CTObjectiveCRuntimeAdditions/*.{h,m}",
                "public_header_files": "Extensions/CTObjectiveCRuntimeAdditions/*.h"
            }
        }
    ]
}

Pin It on Pinterest

Share This