BlocksKit

作者: 946017348a53 | 来源:发表于2017-07-14 15:52 被阅读0次

    开源地址:https://github.com/zwaldowski/BlocksKit

    把很多系统的delegate,方法等 翻新成block 了,对与UIKit 类的,还是比较方便使用的。对于喜欢block的可以考虑试试。(注tableView 这样大个的 delegate 还是算了把骚年)

    简单举几个比较常用的栗子

    UIControl

    [button bk_addEventHandler:^(idsender) {        // do something    } forControlEvents:UIControlEventTouchUpInside];

    UITextField

    [testField setBk_shouldReturnBlock:^BOOL(UITextField*field) {// do something like[self.view endEditing:YES];returnYES;    }];// 类似的还有其他几个代理

    UIView

    [view bk_whenTapped:^{//dosomething//直接添加手势,不需要额外代码    }];//类似还有双击等

    UIWebView

    [webView bk_setDidFinishWithErrorBlock:^(UIWebView*webView,NSError*error) {// do something with error}];// 类似还有其他代理

    KVO

    注:remove 对应出现

    1 生成indentify

    ```

    // 生成的 是 用于移除观察的 indentify

    NSStringtoken = [self.label bk_addObserverForKeyPath:@"text" options:NSKeyValueObservingOptionNew task:^(id obj, NSDictionarychange) {

    NSLog(@"%@",change);NSLog(@"%@",obj);

    }];

    // 移除上面添加的

    [self.label bk_removeObserversWithIdentifier:token];

    -2 直接写indentify,使用感觉比较方便,indentify 可以与通知一样写个 常量。

    [self.labelbk_addObserverForKeyPath:@"test"identifier:@"indentfy"options:NSKeyValueObservingOptionNewtask:^(id obj, NSDictionary *change) {// do something}];[self.labelbk_removeObserversWithIdentifier:@"indentify"];

    -3根据参数不同有另外几个## NSTimer

    [NSTimer bk_scheduledTimerWithTimeInterval:1 block:^(NSTimer*timer) {    // do    NSLog(@"1");} repeats:YES];

    ## NSObject (延迟处理)

    [self bk_performBlock:^(id obj) {

    //do (其实就是 GCD after 方法)

    NSLog(@"1");

    } onQueue:dispatch_get_global_queue(0, 0) afterDelay:2];

    ```

    其他的 对数据类型进行 block,感觉很少用。

    其他动态block ...

    相关文章

      网友评论

          本文标题:BlocksKit

          本文链接:https://www.haomeiwen.com/subject/putbittx.html