MPFastDispatch 0.1.3

MPFastDispatch 0.1.3

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最后发布2014年12月

由Matteo Pacini维护。



MPFastDispatch是GCD的帮助宏集合。

集成

在您的Podfile中添加以下内容:

pod 'MPFastDispatch'

在您的前缀中导入类

#import <MPFastDispatch.h>

宏(目前有)

@once(BLOCK) //"dispatch_once" shorthand
@after(SECONDS,BLOCK)  //"dispatch_after" shorthand
@mainqueue(BLOCK)  //Executes a block on the main queue
@backgroundqueue(BLOCK) // Executes a block on the global background queue

@sem(TAG,VAL)  //Creates a semaphore named "__sem##TAG" with value "VAL"
@sem_signal(TAG) //Increments value of semaphore named "__sem##TAG"
@sem_wait(TAG, TIMEOUT) //Decrements value of semaphore named "__sem##TAG" using timeout "TIMEOUT"

比较

在主队列上异步调度一个块

要在主队列上调度一个块,您将...

dispatch_async(dispatch_get_main_queue(), ^{
    CODE
});

使用MPFastDispatch,您可以这样做:

@mainqueue(^{
    CODE
})

在全局后台队列上异步调度一个块

要在后台队列上调度一个块,您将...

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND,0), ^{
    CODE
});

使用MPFastDispatch,您可以这样做:

@backgroundqueue(^{
    CODE
})

只调度一次块

要只调度一次块,您将...

static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
    CODE
});

使用MPFastDispatch,您可以这样做:

@once(^{
    CODE
})

调度n秒后执行一个块

要只调度一次块,您将...

dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(SECONDS * NSEC_PER_SEC)), 
    dispatch_get_main_queue(), 
    ^{
        CODE
     });

使用MPFastDispatch,您可以这样做:

@after(SECONDS,^{
    CODE
})

信号量快捷方式的使用

@backgroundqueue(^{

    @sem(One, 0)
    @after(5.0f, ^{
        @sem_signal(One)
    });
    @sem_wait(One, DISPATCH_TIME_FOREVER)

    NSLog(@"The end");

});

Swift

不支持Swift,因为它不包含预处理器。

待办事项/贡献

TBW

Fork仓库并发送pull请求!

许可证

Copyright (c) 2014 Matteo Pacini

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.