DFInvocation 1.0.2

DFInvocation 1.0.2

DFInvocation 维护。



  • 作者
  • DevilFinger

DFInvocation

此项目参考了他人的代码,如果使用到您的代码,请通知我。

此项目基于NSInvocation进行开发。一个可以用于多个参数的动态调用函数。同时,获取函数的返回值。

要求

  • iOS 8.0+
  • Objective-C

安装

有两种方式可以在项目中使用DFInvocation

  • 使用CocoaPods
  • 将项目克隆到您的仓库中

使用CocoaPods安装

CocoaPods 是 Objective-C 的依赖管理器,它自动化并简化了在项目中使用第三方库的过程。有关更多详细信息,请参阅入门部分。

Podfile

platform :ios, '8.0'
target "ProjectName" do
pod 'DFInvocation' '1.0.0'
end

## 如何使用 导入头文件

#import "NSObject+DFInvocation.h"

调用无参数的方法,就像这样

[self dfPerformSelector:@selector(customClassMethodWithoutArgument)];

调用只有一个参数的方法,就像这样

NSArray *arguments = @[@"i am argumen 1", @"i am argumen 2"];
NSArray *resutlA = [self dfPerformSelector:@selector(customClassMethodWithOneArgument:) argument:arguments];

如果方法有多个参数,你可以这样调用

NSArray *arguments = @[@"i am argumen 1", @"i am argumen 2"];
NSArray *argumentsEx = @[arguments, @(1), @(CGRectMake(0, 0, 100, 200))];
NSArray *resutlEx = [self dfPerformSelector:@selector(customClassMethodWithManyArguments:argument2:argument3:) arguments:argumentsEx];

当方法参数是代码块时,你可以这样调用

首先,声明 "代码块"

void (^blk)(NSInteger ) = ^(NSInteger count) {
    NSLog(@"block %@", @(count));
};

然后调用 dfPerformSelector 如下

[self  dfPerformSelector:@selector(block:) argument:blk];

同时,如果方法会返回值,"dfPerformSelector" 也会返回它。

## 如何捕获错误 ### 如果你想在执行选择器出错时捕获错误,请将该值更改为 "YES"。默认是 "NO"。

[DFInvocationHelper sharedHelper].isCatchAndThrow = YES;

### 更多用法,请参阅项目中的代码

通信

  • 如果你 发现了错误,请打开一个问题。
  • 如果你 有功能请求,请提出问题。

许可证

所有源代码都遵循 MIT 许可