Code Monkey home page Code Monkey logo

jkgcdtimer's Introduction

JKGCDTimer

GCD定时器的封装

第1种使用方式(block返回执行的任务)

// 导入,这个是封装的类名
#import "JKGCDTimer.h"
@property(nonatomic,strong) NSString *gcdTimerKeyName;
// 第1种使用方式(Block里面做task)

static int number = 0;
/**
  task 定时器开启后执行的任务
  startTime 多长时间后开启任务
  intervalTime 时间间隔
  repeats 是否重复执行任务  YES: 重复  NO: 执行一次
  async 同步还是异步执行任务  YES:async(全局并发队列)  NO: sync(主队列)
 */
self.gcdTimerKeyName = [JKGCDTimer execTask:^{

   number ++;
   NSLog(@"number==%d-------%@",number,[NSThread currentThread]);

} startTime:2.0 intervalTime:1.0 repeats:YES async:YES];

第2种使用方式(在自己的控制器里面的方法 实现任务)

// 导入,这个是封装的类名
#import "JKGCDTimer.h"
@property(nonatomic,strong) NSString *gcdTimerKeyName;
/**
  target 自己VC的 self
  selector 自己VC里面的 方法
  startTime 多长时间后开启任务
  intervalTime 时间间隔
  repeats 是否重复执行任务  YES: 重复  NO: 执行一次
  async 同步还是异步执行任务  YES:async(全局并发队列)  NO: sync(主队列)
*/

self.gcdTimerKeyName = [JKGCDTimer execTaskTarget:self selector:@selector(timerExecTask) startTime:2.0 intervalTime:1.0 repeats:YES async:YES];

#pragma mark 采用自己控制器执行任务的方法
-(void)timerExecTask{

  static int number = 0;
  number ++;
  NSLog(@"number==%d-------%@",number,[NSThread currentThread]);

}

jkgcdtimer's People

Contributors

joanking avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

rbqren000

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.