Giter VIP home page Giter VIP logo

zxctimer's Introduction

ZXClTimer

简介

ZXCTimer是一个全局的定时计时器,能够一行代码添加定时任务或者轮询任务,并且无需人为管理,控制器退出时可直接直接kill本控制器所有的任务

下载&使用

1.直接将目录下'ZXCGlobalTimer'文件夹引入工程中,并且引入NSObject+ZXCTimer.h头文件

循环任务

-(ZXCCyclesQueueItem*)addCycleTask:(dispatch_block_t)callback timeInterval:(NSTimeInterval)time;
-(ZXCCyclesQueueItem*)addCycleTask:(dispatch_block_t)callback timeInterval:(NSTimeInterval)time runCount:(NSInteger)count;
-(ZXCCyclesQueueItem*)addCycleTask:(dispatch_block_t)callback timeInterval:(NSTimeInterval)time threadMode:(ZXCThreadMode)mode;
-(ZXCCyclesQueueItem*)addCycleTask:(dispatch_block_t)callback timeInterval:(NSTimeInterval)time runCount:(NSInteger)count threadMode:(ZXCThreadMode)mode;

-(void)removeCycleTask:(ZXCCyclesQueueItem*)item;
-(void)removeAllCycleTask;

定时任务

-(ZXCTimerQueueItem*)addTimerTask:(dispatch_block_t)callback after:(NSTimeInterval)time;
-(ZXCTimerQueueItem*)addTimerTask:(dispatch_block_t)callback after:(NSTimeInterval)time threadMode:(ZXCThreadMode)mode;

-(void)removeTimerTask:(ZXCTimerQueueItem*)item;
-(void)removeAllTimerTask;

NSObject [ dealloc 时调用]

-(void)removeSelfTasks;

Demo

单例方式 可替换 self方式

------------------------------------------
[self addCycleTask:^{
		NSLog(@"【主线程】循环任务");
    } timeInterval:0.44];


[self addCycleTask:^{
        NSLog(@"【后台】循环任务");
    } timeInterval:1 threadMode:ZXCBackgroundThread];

[self addTimerTask:^{
        NSLog(@"【主线程】定时任务");
    } after:10];
    
[self addTimerTask:^{
        NSLog(@"【后台】定时任务");
    } after:10 threadMode:ZXCBackgroundThread];

End

若有任何问题欢迎发留言

zxctimer's People

Contributors

zhangxuchuan827 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.