├── zygcdtimer.png ├── fastlane ├── Fastfile └── README.md ├── ZYGCDTimerDemo.xcodeproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── project.pbxproj ├── ZYGCDTimerDemo ├── ViewController.h ├── GCDViewController.h ├── AppDelegate.h ├── main.m ├── ViewController.m ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── AppDelegate.m └── GCDViewController.m ├── ZYGCDTimer.podspec ├── LICENSE ├── .gitignore ├── ZYGCDTimer ├── ZYGCDTimer.h └── ZYGCDTimer.m └── README.md /zygcdtimer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ripperhe/ZYGCDTimer/HEAD/zygcdtimer.png -------------------------------------------------------------------------------- /fastlane/Fastfile: -------------------------------------------------------------------------------- 1 | import_from_git(url: 'https://github.com/ripperhe/fastlane-files', branch: 'master') 2 | -------------------------------------------------------------------------------- /ZYGCDTimerDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ZYGCDTimerDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // ZYGCDTimerDemo 4 | // 5 | // Created by ripper on 2017/2/21. 6 | // Copyright © 2017年 ripper. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /ZYGCDTimerDemo/GCDViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // GCDViewController.h 3 | // ZYGCDTimerDemo 4 | // 5 | // GitHub https://github.com/ripperhe 6 | // Created by ripper on 2017/2/21. 7 | // Copyright © 2017年 ripper. All rights reserved. 8 | // 9 | 10 | #import 11 | 12 | @interface GCDViewController : UIViewController 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /ZYGCDTimerDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // ZYGCDTimerDemo 4 | // 5 | // Created by ripper on 2017/2/21. 6 | // Copyright © 2017年 ripper. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /ZYGCDTimerDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // ZYGCDTimerDemo 4 | // 5 | // Created by ripper on 2017/2/21. 6 | // Copyright © 2017年 ripper. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ZYGCDTimerDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // ZYGCDTimerDemo 4 | // 5 | // Created by ripper on 2017/2/21. 6 | // Copyright © 2017年 ripper. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | @interface ViewController () 12 | 13 | @end 14 | 15 | @implementation ViewController 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | // Do any additional setup after loading the view, typically from a nib. 20 | } 21 | 22 | 23 | - (void)didReceiveMemoryWarning { 24 | [super didReceiveMemoryWarning]; 25 | // Dispose of any resources that can be recreated. 26 | } 27 | 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /ZYGCDTimerDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /ZYGCDTimer.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'ZYGCDTimer' 3 | s.version = '1.0.0' 4 | s.summary = "A timer that doesn't retain the target and supports being used with GCD queues" 5 | s.homepage = 'https://github.com/ripperhe/ZYGCDTimer' 6 | 7 | s.license = { :type => 'MIT', :file => 'LICENSE' } 8 | s.author = { 'ripperhe' => 'ripperhe@qq.com' } 9 | s.source = { :git => 'https://github.com/ripperhe/ZYGCDTimer.git', :tag => s.version.to_s } 10 | 11 | s.ios.deployment_target = '8.0' 12 | s.osx.deployment_target = '10.12' 13 | 14 | s.source_files = 'ZYGCDTimer/**/*' 15 | 16 | # s.resource_bundles = { 17 | # 'ZYGCDTimer' => ['ZYGCDTimer/Assets/*.png'] 18 | # } 19 | 20 | # s.public_header_files = 'Pod/Classes/**/*.h' 21 | # s.frameworks = 'UIKit', 'MapKit' 22 | # s.dependency 'AFNetworking', '~> 2.3' 23 | end 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 ripper 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ZYGCDTimerDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /fastlane/README.md: -------------------------------------------------------------------------------- 1 | fastlane documentation 2 | ================ 3 | # Installation 4 | 5 | Make sure you have the latest version of the Xcode command line tools installed: 6 | 7 | ``` 8 | xcode-select --install 9 | ``` 10 | 11 | ## Choose your installation method: 12 | 13 | 14 | 15 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
Homebrew 16 | Installer Script 17 | Rubygems 18 |
macOSmacOSmacOS or Linux with Ruby 2.0.0 or above
brew cask install fastlaneDownload the zip file. Then double click on the install script (or run it in a terminal window).sudo gem install fastlane -NV
30 | # Available Actions 31 | ### release_lib 32 | ``` 33 | fastlane release_lib 34 | ``` 35 | Release new pod version 36 | 37 | ---- 38 | 39 | This README.md is auto-generated and will be re-generated every time [fastlane](https://fastlane.tools) is run. 40 | More information about fastlane can be found on [fastlane.tools](https://fastlane.tools). 41 | The documentation of fastlane can be found on [docs.fastlane.tools](https://docs.fastlane.tools). 42 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | # CocoaPods 31 | # 32 | # We recommend against adding the Pods directory to your .gitignore. However 33 | # you should judge for yourself, the pros and cons are mentioned at: 34 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 35 | # 36 | # Pods/ 37 | 38 | # Carthage 39 | # 40 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 41 | # Carthage/Checkouts 42 | 43 | Carthage/Build 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 51 | 52 | fastlane/report.xml 53 | fastlane/screenshots 54 | 55 | #Code Injection 56 | # 57 | # After new code Injection tools there's a generated folder /iOSInjectionProject 58 | # https://github.com/johnno1962/injectionforxcode 59 | 60 | iOSInjectionProject/ 61 | -------------------------------------------------------------------------------- /ZYGCDTimerDemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /ZYGCDTimer/ZYGCDTimer.h: -------------------------------------------------------------------------------- 1 | // 2 | // ZYGCDTimer.h 3 | // ZYGCDTimerDemo 4 | // 5 | // GitHub https://github.com/ripperhe 6 | // Created by ripper on 2017/2/20. 7 | // Copyright © 2017年 ripper. All rights reserved. 8 | // 9 | 10 | #import 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | @interface ZYGCDTimer : NSObject 15 | 16 | /// 调用时间间隔 17 | @property (readonly) NSTimeInterval interval; 18 | 19 | /// 用户信息 20 | @property (readonly) id _Nullable userInfo; 21 | 22 | /// 容忍度,单位秒,默认为 0.1;即便设置为 0.0 仍然存在误差 23 | @property (atomic, assign) NSTimeInterval tolerance; 24 | 25 | /// 创建一个定时器 26 | /// @param interval 调用的时间间隔 27 | /// @param aTarget 对象 28 | /// @param aSelector 方法选择器 29 | /// @param userInfo 用户信息 30 | /// @param repeats 是否重复 31 | /// @param dispatchQueue 派发事件的队列,可以是串行队列或并发队列 32 | + (instancetype)timerWithTimeInterval:(NSTimeInterval)interval 33 | target:(id)aTarget 34 | selector:(SEL)aSelector 35 | userInfo:(nullable id)userInfo 36 | repeats:(BOOL)repeats 37 | dispatchQueue:(dispatch_queue_t)dispatchQueue; 38 | 39 | /// 创建一个定时器 40 | /// @param interval 调用的时间间隔 41 | /// @param userInfo 用户信息 42 | /// @param repeats 是否重复 43 | /// @param dispatchQueue 派发事件的队列,可以是串行队列或并发队列 44 | /// @param block 定时器事件 45 | + (instancetype)timerWithTimeInterval:(NSTimeInterval)interval 46 | userInfo:(nullable id)userInfo 47 | repeats:(BOOL)repeats 48 | dispatchQueue:(dispatch_queue_t)dispatchQueue 49 | block:(void (^)(ZYGCDTimer *timer))block; 50 | 51 | /// 启用定时器 52 | - (void)fire; 53 | 54 | /// 无效定时器 55 | /// @note 调用该方法之后,将无法重启定时器 56 | /// @note 如果是用 target selector 方式启用的定时器,target 销毁之后的第一次调用 selector 的时机会自动调用本方法 57 | - (void)invalidate; 58 | 59 | /// 暂停定时器 60 | /// @note 调用本方法之后,可以用 fire 重启定时器 61 | - (void)pause; 62 | 63 | @end 64 | 65 | NS_ASSUME_NONNULL_END 66 | -------------------------------------------------------------------------------- /ZYGCDTimerDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // ZYGCDTimerDemo 4 | // 5 | // Created by ripper on 2017/2/21. 6 | // Copyright © 2017年 ripper. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | 24 | - (void)applicationWillResignActive:(UIApplication *)application { 25 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 27 | } 28 | 29 | 30 | - (void)applicationDidEnterBackground:(UIApplication *)application { 31 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application { 37 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 38 | } 39 | 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 43 | } 44 | 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ZYGCDTimer 2 | 3 | [![Version](https://img.shields.io/cocoapods/v/ZYGCDTimer.svg?style=flat)](http://cocoapods.org/pods/ZYGCDTimer) 4 | [![License](https://img.shields.io/cocoapods/l/ZYGCDTimer.svg?style=flat)](http://cocoapods.org/pods/ZYGCDTimer) 5 | [![Platform](https://img.shields.io/cocoapods/p/ZYGCDTimer.svg?style=flat)](http://cocoapods.org/pods/ZYGCDTimer) 6 | 7 | ZYGCDTimer 主要用于替代 `NSTimer`,不会强持有 target,基于 [MSWeakTimer](https://github.com/mindsnacks/MSWeakTimer) 进行修改的,本质上是个 `GCD` 定时器。 8 | 9 | ## Features 10 | 11 | - [x] 弱引用 `target` 12 | - [x] `target` 销毁之后,自动调用 `invalidate` 13 | - [x] 支持 `block` 创建定时器 14 | - [x] 支持设置 `GCD queue` 15 | - [x] 支持暂停定时器 16 | 17 | ## Example 18 | 19 | ![](zygcdtimer.png) 20 | 21 | 下载 demo 直接运行即可 22 | 23 | ## Requirements 24 | 25 | * iOS 8.0+ 26 | * macOS 10.12+ 27 | 28 | ## Installation 29 | 30 | ZYGCDTimer 支持 [CocoaPods](http://cocoapods.org) 安装。在 `Podfile` 中写入以下文本,然后执行 `pod install` 即可: 31 | 32 | ```ruby 33 | pod "ZYGCDTimer" 34 | ``` 35 | 36 | ## Usage 37 | 38 | 使用 `target-selector` 创建定时器 39 | 40 | ```objc 41 | + (instancetype)timerWithTimeInterval:(NSTimeInterval)interval 42 | target:(id)aTarget 43 | selector:(SEL)aSelector 44 | userInfo:(nullable id)userInfo 45 | repeats:(BOOL)repeats 46 | dispatchQueue:(dispatch_queue_t)dispatchQueue; 47 | ``` 48 | 49 | 使用 `block` 创建定时器 50 | 51 | ```objc 52 | + (instancetype)timerWithTimeInterval:(NSTimeInterval)interval 53 | userInfo:(nullable id)userInfo 54 | repeats:(BOOL)repeats 55 | dispatchQueue:(dispatch_queue_t)dispatchQueue 56 | block:(void (^)(ZYGCDTimer *timer))block; 57 | ``` 58 | 59 | 启用定时器 60 | 61 | ```objc 62 | - (void)fire; 63 | ``` 64 | 65 | 无效定时器 66 | 67 | ```objc 68 | - (void)invalidate; 69 | ``` 70 | 71 | 暂停定时器 72 | 73 | ```objc 74 | - (void)pause; 75 | ``` 76 | 77 | ## Author 78 | 79 | ripperhe, ripperhe@qq.com 80 | 81 | ## License 82 | 83 | ZYGCDTimer is available under the MIT license. See the LICENSE file for more info. 84 | -------------------------------------------------------------------------------- /ZYGCDTimerDemo/GCDViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // GCDViewController.m 3 | // ZYGCDTimerDemo 4 | // 5 | // GitHub https://github.com/ripperhe 6 | // Created by ripper on 2017/2/21. 7 | // Copyright © 2017年 ripper. All rights reserved. 8 | // 9 | 10 | #import "GCDViewController.h" 11 | #import "ZYGCDTimer.h" 12 | 13 | @interface GCDViewController () 14 | 15 | @property (weak, nonatomic) IBOutlet UILabel *timeLabel; 16 | 17 | @property (nonatomic, strong) ZYGCDTimer *timer; 18 | @property (nonatomic, strong) ZYGCDTimer *backgroundTimer; 19 | 20 | @property (nonatomic, strong) dispatch_queue_t backgroundQueue; 21 | 22 | @property (nonatomic, assign) NSTimeInterval currentTime;; 23 | 24 | @end 25 | 26 | static const char *BackgroundTimerQueueContext = "BackgroundTimerQueueContext"; 27 | 28 | @implementation GCDViewController 29 | 30 | -(void)dealloc { 31 | NSLog(@"%@ dealloc", self); 32 | } 33 | 34 | - (void)viewDidLoad { 35 | [super viewDidLoad]; 36 | 37 | /* 38 | 1. block 39 | */ 40 | 41 | __weak typeof(self) weakSelf = self; 42 | self.timer = [ZYGCDTimer timerWithTimeInterval:1.0 userInfo:nil repeats:YES dispatchQueue:dispatch_get_main_queue() block:^(ZYGCDTimer * _Nonnull timer) { 43 | __strong typeof(weakSelf) self = weakSelf; 44 | 45 | // block 内部使用 self 都需要对 self 弱引用,否则会强持有 46 | // PS: NSAssert 宏内部使用了 self,所以用 NSAssert 也需要弱引用 47 | NSAssert(NSThread.isMainThread, @"不是主线程"); 48 | self.currentTime += timer.interval; 49 | self.timeLabel.text = [NSString stringWithFormat:@"%f",self.currentTime]; 50 | }]; 51 | self.timer.tolerance = 0.5; 52 | 53 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 54 | self.timer.tolerance = 0.8; 55 | }); 56 | /* 57 | 2. target selector 58 | */ 59 | 60 | self.backgroundQueue = dispatch_queue_create("com.ripperhe.backQueue", DISPATCH_QUEUE_CONCURRENT); 61 | dispatch_queue_set_specific(self.backgroundQueue, (__bridge const void *)(self), (void *)BackgroundTimerQueueContext, NULL); 62 | 63 | self.backgroundTimer = [ZYGCDTimer timerWithTimeInterval:1 64 | target:self 65 | selector:@selector(backgroundTimerCallback:) 66 | userInfo:nil 67 | repeats:YES 68 | dispatchQueue:self.backgroundQueue]; 69 | [self.backgroundTimer fire]; 70 | } 71 | 72 | - (void)backgroundTimerCallback:(ZYGCDTimer *)timer { 73 | NSAssert(![NSThread isMainThread], @"There is background thread"); 74 | 75 | const BOOL result = dispatch_queue_get_specific(self.backgroundQueue, (__bridge const void *)(self)) == BackgroundTimerQueueContext; 76 | 77 | NSAssert(result, @"There should be my background queue"); 78 | 79 | NSLog(@"background queue running ---->"); 80 | } 81 | 82 | 83 | - (IBAction)fire:(id)sender { 84 | [self.timer fire]; 85 | } 86 | 87 | - (IBAction)pause:(id)sender { 88 | [self.timer pause]; 89 | } 90 | 91 | - (IBAction)invalidate:(id)sender { 92 | [self.timer invalidate]; 93 | } 94 | 95 | @end 96 | -------------------------------------------------------------------------------- /ZYGCDTimer/ZYGCDTimer.m: -------------------------------------------------------------------------------- 1 | // 2 | // ZYGCDTimer.m 3 | // ZYGCDTimerDemo 4 | // 5 | // GitHub https://github.com/ripperhe 6 | // Created by ripper on 2017/2/20. 7 | // Copyright © 2017年 ripper. All rights reserved. 8 | // 9 | 10 | #import "ZYGCDTimer.h" 11 | #import 12 | 13 | @interface ZYGCDTimer () { 14 | struct 15 | { 16 | uint32_t timerIsInvalidated; 17 | uint32_t timerIsPaused; 18 | uint32_t timerIsFired; 19 | } _timerFlags; 20 | } 21 | 22 | @property (nonatomic, weak) id target; 23 | @property (nonatomic, assign) SEL selector; 24 | @property (nonatomic, copy) void(^block)(ZYGCDTimer *timer); 25 | 26 | @property (nonatomic, assign) NSTimeInterval interval; 27 | @property (nonatomic, strong) id userInfo; 28 | @property (nonatomic, assign) BOOL isRepeats; 29 | 30 | @property (nonatomic, strong) dispatch_queue_t privateSerialQueue; 31 | @property (nonatomic, strong) dispatch_source_t timer; 32 | 33 | @property (nonatomic, assign) BOOL isTarget; 34 | 35 | @end 36 | 37 | 38 | @implementation ZYGCDTimer 39 | 40 | @synthesize tolerance = _tolerance; 41 | 42 | - (void)dealloc { 43 | NSLog(@"%@ dealloc", self.description); 44 | [self invalidate]; 45 | } 46 | 47 | - (instancetype)initWithTimeInterval:(NSTimeInterval)interval 48 | userInfo:(id)userInfo 49 | repeats:(BOOL)repeats 50 | dispatchQueue:(dispatch_queue_t)dispatchQueue { 51 | if (self = [super init]) { 52 | self.interval = interval; 53 | self.userInfo = userInfo; 54 | self.isRepeats = repeats; 55 | _tolerance = 0.1; 56 | 57 | NSString *privateQueueName = [NSString stringWithFormat:@"com.ripperhe.zygcdtimer.%p", self]; 58 | self.privateSerialQueue = dispatch_queue_create([privateQueueName cStringUsingEncoding:NSASCIIStringEncoding], DISPATCH_QUEUE_SERIAL); 59 | // 将 privateSerialQueue 与 dispatchQueue 串行执行 60 | dispatch_set_target_queue(self.privateSerialQueue, dispatchQueue); 61 | 62 | self.timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 63 | 0, 64 | 0, 65 | self.privateSerialQueue); 66 | 67 | __weak typeof(self) weakSelf = self; 68 | dispatch_source_set_event_handler(self.timer, ^{ 69 | __strong typeof(weakSelf) self = weakSelf; 70 | [self timerCallback]; 71 | }); 72 | dispatch_resume(self.timer); 73 | } 74 | return self; 75 | } 76 | 77 | - (void)resetTime { 78 | int64_t intervalInNanoseconds = (int64_t)(self.interval * NSEC_PER_SEC); 79 | int64_t toleranceInNanoseconds = (int64_t)(self.tolerance * NSEC_PER_SEC); 80 | 81 | dispatch_source_set_timer(self.timer, 82 | dispatch_time(DISPATCH_TIME_NOW, intervalInNanoseconds), 83 | (uint64_t)intervalInNanoseconds, 84 | toleranceInNanoseconds 85 | ); 86 | } 87 | 88 | #pragma mark - API 89 | + (instancetype)timerWithTimeInterval:(NSTimeInterval)interval 90 | target:(nonnull id)aTarget 91 | selector:(nonnull SEL)aSelector 92 | userInfo:(id)userInfo 93 | repeats:(BOOL)repeats 94 | dispatchQueue:(dispatch_queue_t)dispatchQueue { 95 | NSParameterAssert(aTarget); 96 | NSParameterAssert(aSelector); 97 | NSParameterAssert(dispatchQueue); 98 | 99 | ZYGCDTimer *timer = [[ZYGCDTimer alloc] initWithTimeInterval:interval userInfo:userInfo repeats:repeats dispatchQueue:dispatchQueue]; 100 | timer.target = aTarget; 101 | timer.selector = aSelector; 102 | timer.isTarget = YES; 103 | return timer; 104 | } 105 | 106 | + (instancetype)timerWithTimeInterval:(NSTimeInterval)interval 107 | userInfo:(id)userInfo 108 | repeats:(BOOL)repeats 109 | dispatchQueue:(dispatch_queue_t)dispatchQueue 110 | block:(nonnull void (^)(ZYGCDTimer * _Nonnull))block { 111 | NSParameterAssert(block); 112 | NSParameterAssert(dispatchQueue); 113 | 114 | ZYGCDTimer *timer = [[ZYGCDTimer alloc] initWithTimeInterval:interval userInfo:userInfo repeats:repeats dispatchQueue:dispatchQueue]; 115 | timer.block = block; 116 | timer.isTarget = NO; 117 | return timer; 118 | } 119 | 120 | - (void)fire { 121 | #pragma clang diagnostic push 122 | #pragma clang diagnostic ignored"-Wdeprecated-declarations" 123 | if (OSAtomicAnd32OrigBarrier(1, &_timerFlags.timerIsInvalidated)) return; 124 | 125 | if (OSAtomicTestAndSetBarrier(7, &_timerFlags.timerIsFired)) return; 126 | 127 | if (OSAtomicTestAndClear(7, &_timerFlags.timerIsPaused)) { 128 | #pragma clang diagnostic pop 129 | self.timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 130 | 0, 131 | 0, 132 | self.privateSerialQueue); 133 | 134 | __weak typeof(self) weakSelf = self; 135 | dispatch_source_set_event_handler(self.timer, ^{ 136 | __strong typeof(weakSelf) self = weakSelf; 137 | [self timerCallback]; 138 | }); 139 | dispatch_source_t timer = self.timer; 140 | dispatch_async(self.privateSerialQueue, ^{ 141 | dispatch_resume(timer); 142 | }); 143 | } 144 | [self resetTime]; 145 | } 146 | 147 | - (void)invalidate { 148 | #pragma clang diagnostic push 149 | #pragma clang diagnostic ignored"-Wdeprecated-declarations" 150 | if (!OSAtomicTestAndSetBarrier(7, &_timerFlags.timerIsInvalidated)) { 151 | OSAtomicTestAndClear(7, &_timerFlags.timerIsFired); 152 | #pragma clang diagnostic pop 153 | dispatch_source_t timer = self.timer; 154 | dispatch_async(self.privateSerialQueue, ^{ 155 | dispatch_source_cancel(timer); 156 | }); 157 | } 158 | } 159 | 160 | - (void)pause { 161 | /* 162 | dispatch_resume() 与 dispatch_suspend() 是平衡挂起计数的 163 | 164 | 当一个 dispatch 的 timer 对象为挂起状态,被销毁会导致程序崩溃,所以这里采用重新创建 timer 的方式实现 pause 功能 165 | */ 166 | #pragma clang diagnostic push 167 | #pragma clang diagnostic ignored"-Wdeprecated-declarations" 168 | if (OSAtomicAnd32OrigBarrier(1, &_timerFlags.timerIsInvalidated) || !OSAtomicAnd32OrigBarrier(1, &_timerFlags.timerIsFired)) return; 169 | 170 | if (!OSAtomicTestAndSetBarrier(7, &_timerFlags.timerIsPaused)) { 171 | OSAtomicTestAndClear(7, &_timerFlags.timerIsFired); 172 | dispatch_source_t timer = self.timer; 173 | dispatch_async(self.privateSerialQueue, ^{ 174 | dispatch_source_cancel(timer); 175 | }); 176 | } 177 | #pragma clang diagnostic pop 178 | } 179 | 180 | - (void)setTolerance:(NSTimeInterval)tolerance { 181 | @synchronized(self) { 182 | if (tolerance != _tolerance) { 183 | _tolerance = tolerance; 184 | [self resetTime]; 185 | } 186 | } 187 | } 188 | 189 | - (NSTimeInterval)tolerance { 190 | @synchronized(self) { 191 | return _tolerance; 192 | } 193 | } 194 | 195 | #pragma mark - timer callback 196 | 197 | - (void)timerCallback { 198 | #pragma clang diagnostic push 199 | #pragma clang diagnostic ignored"-Wdeprecated-declarations" 200 | if (OSAtomicAnd32OrigBarrier(1, &_timerFlags.timerIsInvalidated) || 201 | OSAtomicAnd32OrigBarrier(1, &_timerFlags.timerIsPaused)) { 202 | return; 203 | } 204 | #pragma clang diagnostic pop 205 | 206 | if (self.isTarget) { 207 | if (self.target) { 208 | #pragma clang diagnostic push 209 | #pragma clang diagnostic ignored "-Warc-performSelector-leaks" 210 | id target = self.target; 211 | [target performSelector:self.selector withObject:self]; 212 | #pragma clang diagnostic pop 213 | }else { 214 | [self invalidate]; 215 | } 216 | }else { 217 | if (self.block) { 218 | self.block(self); 219 | }else { 220 | [self invalidate]; 221 | } 222 | } 223 | 224 | if (!self.isRepeats) { 225 | [self invalidate]; 226 | } 227 | } 228 | 229 | @end 230 | -------------------------------------------------------------------------------- /ZYGCDTimerDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 77 | 92 | 107 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /ZYGCDTimerDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | C96A96F61E5BEC4400A8BA4E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = C96A96F51E5BEC4400A8BA4E /* main.m */; }; 11 | C96A96F91E5BEC4400A8BA4E /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C96A96F81E5BEC4400A8BA4E /* AppDelegate.m */; }; 12 | C96A96FC1E5BEC4400A8BA4E /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C96A96FB1E5BEC4400A8BA4E /* ViewController.m */; }; 13 | C96A96FF1E5BEC4400A8BA4E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C96A96FD1E5BEC4400A8BA4E /* Main.storyboard */; }; 14 | C96A97011E5BEC4400A8BA4E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C96A97001E5BEC4400A8BA4E /* Assets.xcassets */; }; 15 | C96A97041E5BEC4400A8BA4E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C96A97021E5BEC4400A8BA4E /* LaunchScreen.storyboard */; }; 16 | C96A972A1E5BEC7D00A8BA4E /* ZYGCDTimer.m in Sources */ = {isa = PBXBuildFile; fileRef = C96A97291E5BEC7D00A8BA4E /* ZYGCDTimer.m */; }; 17 | C96A972E1E5C095000A8BA4E /* GCDViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C96A972D1E5C095000A8BA4E /* GCDViewController.m */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXContainerItemProxy section */ 21 | C96A970B1E5BEC4400A8BA4E /* PBXContainerItemProxy */ = { 22 | isa = PBXContainerItemProxy; 23 | containerPortal = C96A96E91E5BEC4400A8BA4E /* Project object */; 24 | proxyType = 1; 25 | remoteGlobalIDString = C96A96F01E5BEC4400A8BA4E; 26 | remoteInfo = ZYGCDTimerDemo; 27 | }; 28 | C96A97161E5BEC4400A8BA4E /* PBXContainerItemProxy */ = { 29 | isa = PBXContainerItemProxy; 30 | containerPortal = C96A96E91E5BEC4400A8BA4E /* Project object */; 31 | proxyType = 1; 32 | remoteGlobalIDString = C96A96F01E5BEC4400A8BA4E; 33 | remoteInfo = ZYGCDTimerDemo; 34 | }; 35 | /* End PBXContainerItemProxy section */ 36 | 37 | /* Begin PBXFileReference section */ 38 | C96A96F11E5BEC4400A8BA4E /* ZYGCDTimerDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ZYGCDTimerDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 39 | C96A96F51E5BEC4400A8BA4E /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 40 | C96A96F71E5BEC4400A8BA4E /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 41 | C96A96F81E5BEC4400A8BA4E /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 42 | C96A96FA1E5BEC4400A8BA4E /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 43 | C96A96FB1E5BEC4400A8BA4E /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 44 | C96A96FE1E5BEC4400A8BA4E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 45 | C96A97001E5BEC4400A8BA4E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 46 | C96A97031E5BEC4400A8BA4E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 47 | C96A97051E5BEC4400A8BA4E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 48 | C96A970A1E5BEC4400A8BA4E /* ZYGCDTimerDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ZYGCDTimerDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 49 | C96A97151E5BEC4400A8BA4E /* ZYGCDTimerDemoUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ZYGCDTimerDemoUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 50 | C96A97281E5BEC7D00A8BA4E /* ZYGCDTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZYGCDTimer.h; sourceTree = ""; }; 51 | C96A97291E5BEC7D00A8BA4E /* ZYGCDTimer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZYGCDTimer.m; sourceTree = ""; }; 52 | C96A972C1E5C095000A8BA4E /* GCDViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDViewController.h; sourceTree = ""; }; 53 | C96A972D1E5C095000A8BA4E /* GCDViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDViewController.m; sourceTree = ""; }; 54 | /* End PBXFileReference section */ 55 | 56 | /* Begin PBXFrameworksBuildPhase section */ 57 | C96A96EE1E5BEC4400A8BA4E /* Frameworks */ = { 58 | isa = PBXFrameworksBuildPhase; 59 | buildActionMask = 2147483647; 60 | files = ( 61 | ); 62 | runOnlyForDeploymentPostprocessing = 0; 63 | }; 64 | C96A97071E5BEC4400A8BA4E /* Frameworks */ = { 65 | isa = PBXFrameworksBuildPhase; 66 | buildActionMask = 2147483647; 67 | files = ( 68 | ); 69 | runOnlyForDeploymentPostprocessing = 0; 70 | }; 71 | C96A97121E5BEC4400A8BA4E /* Frameworks */ = { 72 | isa = PBXFrameworksBuildPhase; 73 | buildActionMask = 2147483647; 74 | files = ( 75 | ); 76 | runOnlyForDeploymentPostprocessing = 0; 77 | }; 78 | /* End PBXFrameworksBuildPhase section */ 79 | 80 | /* Begin PBXGroup section */ 81 | C96A96E81E5BEC4400A8BA4E = { 82 | isa = PBXGroup; 83 | children = ( 84 | C96A97271E5BEC7100A8BA4E /* ZYGCDTimer */, 85 | C96A96F31E5BEC4400A8BA4E /* ZYGCDTimerDemo */, 86 | C96A96F21E5BEC4400A8BA4E /* Products */, 87 | ); 88 | sourceTree = ""; 89 | }; 90 | C96A96F21E5BEC4400A8BA4E /* Products */ = { 91 | isa = PBXGroup; 92 | children = ( 93 | C96A96F11E5BEC4400A8BA4E /* ZYGCDTimerDemo.app */, 94 | C96A970A1E5BEC4400A8BA4E /* ZYGCDTimerDemoTests.xctest */, 95 | C96A97151E5BEC4400A8BA4E /* ZYGCDTimerDemoUITests.xctest */, 96 | ); 97 | name = Products; 98 | sourceTree = ""; 99 | }; 100 | C96A96F31E5BEC4400A8BA4E /* ZYGCDTimerDemo */ = { 101 | isa = PBXGroup; 102 | children = ( 103 | C96A96F71E5BEC4400A8BA4E /* AppDelegate.h */, 104 | C96A96F81E5BEC4400A8BA4E /* AppDelegate.m */, 105 | C96A96FA1E5BEC4400A8BA4E /* ViewController.h */, 106 | C96A96FB1E5BEC4400A8BA4E /* ViewController.m */, 107 | C96A972C1E5C095000A8BA4E /* GCDViewController.h */, 108 | C96A972D1E5C095000A8BA4E /* GCDViewController.m */, 109 | C96A96FD1E5BEC4400A8BA4E /* Main.storyboard */, 110 | C96A97001E5BEC4400A8BA4E /* Assets.xcassets */, 111 | C96A97021E5BEC4400A8BA4E /* LaunchScreen.storyboard */, 112 | C96A97051E5BEC4400A8BA4E /* Info.plist */, 113 | C96A96F41E5BEC4400A8BA4E /* Supporting Files */, 114 | ); 115 | path = ZYGCDTimerDemo; 116 | sourceTree = ""; 117 | }; 118 | C96A96F41E5BEC4400A8BA4E /* Supporting Files */ = { 119 | isa = PBXGroup; 120 | children = ( 121 | C96A96F51E5BEC4400A8BA4E /* main.m */, 122 | ); 123 | name = "Supporting Files"; 124 | sourceTree = ""; 125 | }; 126 | C96A97271E5BEC7100A8BA4E /* ZYGCDTimer */ = { 127 | isa = PBXGroup; 128 | children = ( 129 | C96A97281E5BEC7D00A8BA4E /* ZYGCDTimer.h */, 130 | C96A97291E5BEC7D00A8BA4E /* ZYGCDTimer.m */, 131 | ); 132 | path = ZYGCDTimer; 133 | sourceTree = ""; 134 | }; 135 | /* End PBXGroup section */ 136 | 137 | /* Begin PBXNativeTarget section */ 138 | C96A96F01E5BEC4400A8BA4E /* ZYGCDTimerDemo */ = { 139 | isa = PBXNativeTarget; 140 | buildConfigurationList = C96A971E1E5BEC4400A8BA4E /* Build configuration list for PBXNativeTarget "ZYGCDTimerDemo" */; 141 | buildPhases = ( 142 | C96A96ED1E5BEC4400A8BA4E /* Sources */, 143 | C96A96EE1E5BEC4400A8BA4E /* Frameworks */, 144 | C96A96EF1E5BEC4400A8BA4E /* Resources */, 145 | ); 146 | buildRules = ( 147 | ); 148 | dependencies = ( 149 | ); 150 | name = ZYGCDTimerDemo; 151 | productName = ZYGCDTimerDemo; 152 | productReference = C96A96F11E5BEC4400A8BA4E /* ZYGCDTimerDemo.app */; 153 | productType = "com.apple.product-type.application"; 154 | }; 155 | C96A97091E5BEC4400A8BA4E /* ZYGCDTimerDemoTests */ = { 156 | isa = PBXNativeTarget; 157 | buildConfigurationList = C96A97211E5BEC4400A8BA4E /* Build configuration list for PBXNativeTarget "ZYGCDTimerDemoTests" */; 158 | buildPhases = ( 159 | C96A97061E5BEC4400A8BA4E /* Sources */, 160 | C96A97071E5BEC4400A8BA4E /* Frameworks */, 161 | C96A97081E5BEC4400A8BA4E /* Resources */, 162 | ); 163 | buildRules = ( 164 | ); 165 | dependencies = ( 166 | C96A970C1E5BEC4400A8BA4E /* PBXTargetDependency */, 167 | ); 168 | name = ZYGCDTimerDemoTests; 169 | productName = ZYGCDTimerDemoTests; 170 | productReference = C96A970A1E5BEC4400A8BA4E /* ZYGCDTimerDemoTests.xctest */; 171 | productType = "com.apple.product-type.bundle.unit-test"; 172 | }; 173 | C96A97141E5BEC4400A8BA4E /* ZYGCDTimerDemoUITests */ = { 174 | isa = PBXNativeTarget; 175 | buildConfigurationList = C96A97241E5BEC4400A8BA4E /* Build configuration list for PBXNativeTarget "ZYGCDTimerDemoUITests" */; 176 | buildPhases = ( 177 | C96A97111E5BEC4400A8BA4E /* Sources */, 178 | C96A97121E5BEC4400A8BA4E /* Frameworks */, 179 | C96A97131E5BEC4400A8BA4E /* Resources */, 180 | ); 181 | buildRules = ( 182 | ); 183 | dependencies = ( 184 | C96A97171E5BEC4400A8BA4E /* PBXTargetDependency */, 185 | ); 186 | name = ZYGCDTimerDemoUITests; 187 | productName = ZYGCDTimerDemoUITests; 188 | productReference = C96A97151E5BEC4400A8BA4E /* ZYGCDTimerDemoUITests.xctest */; 189 | productType = "com.apple.product-type.bundle.ui-testing"; 190 | }; 191 | /* End PBXNativeTarget section */ 192 | 193 | /* Begin PBXProject section */ 194 | C96A96E91E5BEC4400A8BA4E /* Project object */ = { 195 | isa = PBXProject; 196 | attributes = { 197 | LastUpgradeCheck = 0820; 198 | ORGANIZATIONNAME = ripper; 199 | TargetAttributes = { 200 | C96A96F01E5BEC4400A8BA4E = { 201 | CreatedOnToolsVersion = 8.2.1; 202 | ProvisioningStyle = Automatic; 203 | }; 204 | C96A97091E5BEC4400A8BA4E = { 205 | CreatedOnToolsVersion = 8.2.1; 206 | ProvisioningStyle = Automatic; 207 | TestTargetID = C96A96F01E5BEC4400A8BA4E; 208 | }; 209 | C96A97141E5BEC4400A8BA4E = { 210 | CreatedOnToolsVersion = 8.2.1; 211 | ProvisioningStyle = Automatic; 212 | TestTargetID = C96A96F01E5BEC4400A8BA4E; 213 | }; 214 | }; 215 | }; 216 | buildConfigurationList = C96A96EC1E5BEC4400A8BA4E /* Build configuration list for PBXProject "ZYGCDTimerDemo" */; 217 | compatibilityVersion = "Xcode 3.2"; 218 | developmentRegion = English; 219 | hasScannedForEncodings = 0; 220 | knownRegions = ( 221 | en, 222 | Base, 223 | ); 224 | mainGroup = C96A96E81E5BEC4400A8BA4E; 225 | productRefGroup = C96A96F21E5BEC4400A8BA4E /* Products */; 226 | projectDirPath = ""; 227 | projectRoot = ""; 228 | targets = ( 229 | C96A96F01E5BEC4400A8BA4E /* ZYGCDTimerDemo */, 230 | C96A97091E5BEC4400A8BA4E /* ZYGCDTimerDemoTests */, 231 | C96A97141E5BEC4400A8BA4E /* ZYGCDTimerDemoUITests */, 232 | ); 233 | }; 234 | /* End PBXProject section */ 235 | 236 | /* Begin PBXResourcesBuildPhase section */ 237 | C96A96EF1E5BEC4400A8BA4E /* Resources */ = { 238 | isa = PBXResourcesBuildPhase; 239 | buildActionMask = 2147483647; 240 | files = ( 241 | C96A97041E5BEC4400A8BA4E /* LaunchScreen.storyboard in Resources */, 242 | C96A97011E5BEC4400A8BA4E /* Assets.xcassets in Resources */, 243 | C96A96FF1E5BEC4400A8BA4E /* Main.storyboard in Resources */, 244 | ); 245 | runOnlyForDeploymentPostprocessing = 0; 246 | }; 247 | C96A97081E5BEC4400A8BA4E /* Resources */ = { 248 | isa = PBXResourcesBuildPhase; 249 | buildActionMask = 2147483647; 250 | files = ( 251 | ); 252 | runOnlyForDeploymentPostprocessing = 0; 253 | }; 254 | C96A97131E5BEC4400A8BA4E /* Resources */ = { 255 | isa = PBXResourcesBuildPhase; 256 | buildActionMask = 2147483647; 257 | files = ( 258 | ); 259 | runOnlyForDeploymentPostprocessing = 0; 260 | }; 261 | /* End PBXResourcesBuildPhase section */ 262 | 263 | /* Begin PBXSourcesBuildPhase section */ 264 | C96A96ED1E5BEC4400A8BA4E /* Sources */ = { 265 | isa = PBXSourcesBuildPhase; 266 | buildActionMask = 2147483647; 267 | files = ( 268 | C96A96FC1E5BEC4400A8BA4E /* ViewController.m in Sources */, 269 | C96A972A1E5BEC7D00A8BA4E /* ZYGCDTimer.m in Sources */, 270 | C96A96F91E5BEC4400A8BA4E /* AppDelegate.m in Sources */, 271 | C96A972E1E5C095000A8BA4E /* GCDViewController.m in Sources */, 272 | C96A96F61E5BEC4400A8BA4E /* main.m in Sources */, 273 | ); 274 | runOnlyForDeploymentPostprocessing = 0; 275 | }; 276 | C96A97061E5BEC4400A8BA4E /* Sources */ = { 277 | isa = PBXSourcesBuildPhase; 278 | buildActionMask = 2147483647; 279 | files = ( 280 | ); 281 | runOnlyForDeploymentPostprocessing = 0; 282 | }; 283 | C96A97111E5BEC4400A8BA4E /* Sources */ = { 284 | isa = PBXSourcesBuildPhase; 285 | buildActionMask = 2147483647; 286 | files = ( 287 | ); 288 | runOnlyForDeploymentPostprocessing = 0; 289 | }; 290 | /* End PBXSourcesBuildPhase section */ 291 | 292 | /* Begin PBXTargetDependency section */ 293 | C96A970C1E5BEC4400A8BA4E /* PBXTargetDependency */ = { 294 | isa = PBXTargetDependency; 295 | target = C96A96F01E5BEC4400A8BA4E /* ZYGCDTimerDemo */; 296 | targetProxy = C96A970B1E5BEC4400A8BA4E /* PBXContainerItemProxy */; 297 | }; 298 | C96A97171E5BEC4400A8BA4E /* PBXTargetDependency */ = { 299 | isa = PBXTargetDependency; 300 | target = C96A96F01E5BEC4400A8BA4E /* ZYGCDTimerDemo */; 301 | targetProxy = C96A97161E5BEC4400A8BA4E /* PBXContainerItemProxy */; 302 | }; 303 | /* End PBXTargetDependency section */ 304 | 305 | /* Begin PBXVariantGroup section */ 306 | C96A96FD1E5BEC4400A8BA4E /* Main.storyboard */ = { 307 | isa = PBXVariantGroup; 308 | children = ( 309 | C96A96FE1E5BEC4400A8BA4E /* Base */, 310 | ); 311 | name = Main.storyboard; 312 | sourceTree = ""; 313 | }; 314 | C96A97021E5BEC4400A8BA4E /* LaunchScreen.storyboard */ = { 315 | isa = PBXVariantGroup; 316 | children = ( 317 | C96A97031E5BEC4400A8BA4E /* Base */, 318 | ); 319 | name = LaunchScreen.storyboard; 320 | sourceTree = ""; 321 | }; 322 | /* End PBXVariantGroup section */ 323 | 324 | /* Begin XCBuildConfiguration section */ 325 | C96A971C1E5BEC4400A8BA4E /* Debug */ = { 326 | isa = XCBuildConfiguration; 327 | buildSettings = { 328 | ALWAYS_SEARCH_USER_PATHS = NO; 329 | CLANG_ANALYZER_NONNULL = YES; 330 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 331 | CLANG_CXX_LIBRARY = "libc++"; 332 | CLANG_ENABLE_MODULES = YES; 333 | CLANG_ENABLE_OBJC_ARC = YES; 334 | CLANG_WARN_BOOL_CONVERSION = YES; 335 | CLANG_WARN_CONSTANT_CONVERSION = YES; 336 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 337 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 338 | CLANG_WARN_EMPTY_BODY = YES; 339 | CLANG_WARN_ENUM_CONVERSION = YES; 340 | CLANG_WARN_INFINITE_RECURSION = YES; 341 | CLANG_WARN_INT_CONVERSION = YES; 342 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 343 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 344 | CLANG_WARN_UNREACHABLE_CODE = YES; 345 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 346 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 347 | COPY_PHASE_STRIP = NO; 348 | DEBUG_INFORMATION_FORMAT = dwarf; 349 | ENABLE_STRICT_OBJC_MSGSEND = YES; 350 | ENABLE_TESTABILITY = YES; 351 | GCC_C_LANGUAGE_STANDARD = gnu99; 352 | GCC_DYNAMIC_NO_PIC = NO; 353 | GCC_NO_COMMON_BLOCKS = YES; 354 | GCC_OPTIMIZATION_LEVEL = 0; 355 | GCC_PREPROCESSOR_DEFINITIONS = ( 356 | "DEBUG=1", 357 | "$(inherited)", 358 | ); 359 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 360 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 361 | GCC_WARN_UNDECLARED_SELECTOR = YES; 362 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 363 | GCC_WARN_UNUSED_FUNCTION = YES; 364 | GCC_WARN_UNUSED_VARIABLE = YES; 365 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 366 | MTL_ENABLE_DEBUG_INFO = YES; 367 | ONLY_ACTIVE_ARCH = YES; 368 | SDKROOT = iphoneos; 369 | }; 370 | name = Debug; 371 | }; 372 | C96A971D1E5BEC4400A8BA4E /* Release */ = { 373 | isa = XCBuildConfiguration; 374 | buildSettings = { 375 | ALWAYS_SEARCH_USER_PATHS = NO; 376 | CLANG_ANALYZER_NONNULL = YES; 377 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 378 | CLANG_CXX_LIBRARY = "libc++"; 379 | CLANG_ENABLE_MODULES = YES; 380 | CLANG_ENABLE_OBJC_ARC = YES; 381 | CLANG_WARN_BOOL_CONVERSION = YES; 382 | CLANG_WARN_CONSTANT_CONVERSION = YES; 383 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 384 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 385 | CLANG_WARN_EMPTY_BODY = YES; 386 | CLANG_WARN_ENUM_CONVERSION = YES; 387 | CLANG_WARN_INFINITE_RECURSION = YES; 388 | CLANG_WARN_INT_CONVERSION = YES; 389 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 390 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 391 | CLANG_WARN_UNREACHABLE_CODE = YES; 392 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 393 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 394 | COPY_PHASE_STRIP = NO; 395 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 396 | ENABLE_NS_ASSERTIONS = NO; 397 | ENABLE_STRICT_OBJC_MSGSEND = YES; 398 | GCC_C_LANGUAGE_STANDARD = gnu99; 399 | GCC_NO_COMMON_BLOCKS = YES; 400 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 401 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 402 | GCC_WARN_UNDECLARED_SELECTOR = YES; 403 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 404 | GCC_WARN_UNUSED_FUNCTION = YES; 405 | GCC_WARN_UNUSED_VARIABLE = YES; 406 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 407 | MTL_ENABLE_DEBUG_INFO = NO; 408 | SDKROOT = iphoneos; 409 | VALIDATE_PRODUCT = YES; 410 | }; 411 | name = Release; 412 | }; 413 | C96A971F1E5BEC4400A8BA4E /* Debug */ = { 414 | isa = XCBuildConfiguration; 415 | buildSettings = { 416 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 417 | INFOPLIST_FILE = ZYGCDTimerDemo/Info.plist; 418 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 419 | PRODUCT_BUNDLE_IDENTIFIER = com.ripperhe.ZYGCDTimerDemo; 420 | PRODUCT_NAME = "$(TARGET_NAME)"; 421 | }; 422 | name = Debug; 423 | }; 424 | C96A97201E5BEC4400A8BA4E /* Release */ = { 425 | isa = XCBuildConfiguration; 426 | buildSettings = { 427 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 428 | INFOPLIST_FILE = ZYGCDTimerDemo/Info.plist; 429 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 430 | PRODUCT_BUNDLE_IDENTIFIER = com.ripperhe.ZYGCDTimerDemo; 431 | PRODUCT_NAME = "$(TARGET_NAME)"; 432 | }; 433 | name = Release; 434 | }; 435 | C96A97221E5BEC4400A8BA4E /* Debug */ = { 436 | isa = XCBuildConfiguration; 437 | buildSettings = { 438 | BUNDLE_LOADER = "$(TEST_HOST)"; 439 | INFOPLIST_FILE = ZYGCDTimerDemoTests/Info.plist; 440 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 441 | PRODUCT_BUNDLE_IDENTIFIER = com.ripperhe.ZYGCDTimerDemoTests; 442 | PRODUCT_NAME = "$(TARGET_NAME)"; 443 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ZYGCDTimerDemo.app/ZYGCDTimerDemo"; 444 | }; 445 | name = Debug; 446 | }; 447 | C96A97231E5BEC4400A8BA4E /* Release */ = { 448 | isa = XCBuildConfiguration; 449 | buildSettings = { 450 | BUNDLE_LOADER = "$(TEST_HOST)"; 451 | INFOPLIST_FILE = ZYGCDTimerDemoTests/Info.plist; 452 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 453 | PRODUCT_BUNDLE_IDENTIFIER = com.ripperhe.ZYGCDTimerDemoTests; 454 | PRODUCT_NAME = "$(TARGET_NAME)"; 455 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ZYGCDTimerDemo.app/ZYGCDTimerDemo"; 456 | }; 457 | name = Release; 458 | }; 459 | C96A97251E5BEC4400A8BA4E /* Debug */ = { 460 | isa = XCBuildConfiguration; 461 | buildSettings = { 462 | INFOPLIST_FILE = ZYGCDTimerDemoUITests/Info.plist; 463 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 464 | PRODUCT_BUNDLE_IDENTIFIER = com.ripperhe.ZYGCDTimerDemoUITests; 465 | PRODUCT_NAME = "$(TARGET_NAME)"; 466 | TEST_TARGET_NAME = ZYGCDTimerDemo; 467 | }; 468 | name = Debug; 469 | }; 470 | C96A97261E5BEC4400A8BA4E /* Release */ = { 471 | isa = XCBuildConfiguration; 472 | buildSettings = { 473 | INFOPLIST_FILE = ZYGCDTimerDemoUITests/Info.plist; 474 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 475 | PRODUCT_BUNDLE_IDENTIFIER = com.ripperhe.ZYGCDTimerDemoUITests; 476 | PRODUCT_NAME = "$(TARGET_NAME)"; 477 | TEST_TARGET_NAME = ZYGCDTimerDemo; 478 | }; 479 | name = Release; 480 | }; 481 | /* End XCBuildConfiguration section */ 482 | 483 | /* Begin XCConfigurationList section */ 484 | C96A96EC1E5BEC4400A8BA4E /* Build configuration list for PBXProject "ZYGCDTimerDemo" */ = { 485 | isa = XCConfigurationList; 486 | buildConfigurations = ( 487 | C96A971C1E5BEC4400A8BA4E /* Debug */, 488 | C96A971D1E5BEC4400A8BA4E /* Release */, 489 | ); 490 | defaultConfigurationIsVisible = 0; 491 | defaultConfigurationName = Release; 492 | }; 493 | C96A971E1E5BEC4400A8BA4E /* Build configuration list for PBXNativeTarget "ZYGCDTimerDemo" */ = { 494 | isa = XCConfigurationList; 495 | buildConfigurations = ( 496 | C96A971F1E5BEC4400A8BA4E /* Debug */, 497 | C96A97201E5BEC4400A8BA4E /* Release */, 498 | ); 499 | defaultConfigurationIsVisible = 0; 500 | defaultConfigurationName = Release; 501 | }; 502 | C96A97211E5BEC4400A8BA4E /* Build configuration list for PBXNativeTarget "ZYGCDTimerDemoTests" */ = { 503 | isa = XCConfigurationList; 504 | buildConfigurations = ( 505 | C96A97221E5BEC4400A8BA4E /* Debug */, 506 | C96A97231E5BEC4400A8BA4E /* Release */, 507 | ); 508 | defaultConfigurationIsVisible = 0; 509 | defaultConfigurationName = Release; 510 | }; 511 | C96A97241E5BEC4400A8BA4E /* Build configuration list for PBXNativeTarget "ZYGCDTimerDemoUITests" */ = { 512 | isa = XCConfigurationList; 513 | buildConfigurations = ( 514 | C96A97251E5BEC4400A8BA4E /* Debug */, 515 | C96A97261E5BEC4400A8BA4E /* Release */, 516 | ); 517 | defaultConfigurationIsVisible = 0; 518 | defaultConfigurationName = Release; 519 | }; 520 | /* End XCConfigurationList section */ 521 | }; 522 | rootObject = C96A96E91E5BEC4400A8BA4E /* Project object */; 523 | } 524 | --------------------------------------------------------------------------------