├── README.md ├── GCDDemo ├── GCDDemo.xcodeproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── project.pbxproj ├── GCDDemo │ ├── ViewController.h │ ├── AppDelegate.h │ ├── main.m │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Info.plist │ ├── Base.lproj │ │ ├── Main.storyboard │ │ └── LaunchScreen.storyboard │ ├── AppDelegate.m │ └── ViewController.m ├── GCDDemoTests │ ├── Info.plist │ └── GCDDemoTests.m └── GCDDemoUITests │ ├── Info.plist │ └── GCDDemoUITests.m ├── .gitignore └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # GCDDemo 2 | 为文章[细说GCD(Grand Central Dispatch)如何用](https://github.com/ming1016/study/wiki/细说GCD(Grand-Central-Dispatch)如何用) 准备的demo 3 | -------------------------------------------------------------------------------- /GCDDemo/GCDDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /GCDDemo/GCDDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // GCDDemo 4 | // 5 | // Created by DaiMing on 16/1/13. 6 | // Copyright © 2016年 Starming. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /GCDDemo/GCDDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // GCDDemo 4 | // 5 | // Created by DaiMing on 16/1/13. 6 | // Copyright © 2016年 Starming. 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 | -------------------------------------------------------------------------------- /GCDDemo/GCDDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // GCDDemo 4 | // 5 | // Created by DaiMing on 16/1/13. 6 | // Copyright © 2016年 Starming. 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 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | #Pods/ 27 | -------------------------------------------------------------------------------- /GCDDemo/GCDDemo/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 | } -------------------------------------------------------------------------------- /GCDDemo/GCDDemoTests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /GCDDemo/GCDDemoUITests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /GCDDemo/GCDDemoTests/GCDDemoTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // GCDDemoTests.m 3 | // GCDDemoTests 4 | // 5 | // Created by DaiMing on 16/1/13. 6 | // Copyright © 2016年 Starming. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface GCDDemoTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation GCDDemoTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 戴铭 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 | -------------------------------------------------------------------------------- /GCDDemo/GCDDemo/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 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /GCDDemo/GCDDemoUITests/GCDDemoUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // GCDDemoUITests.m 3 | // GCDDemoUITests 4 | // 5 | // Created by DaiMing on 16/1/13. 6 | // Copyright © 2016年 Starming. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface GCDDemoUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation GCDDemoUITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /GCDDemo/GCDDemo/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 | 26 | -------------------------------------------------------------------------------- /GCDDemo/GCDDemo/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 | -------------------------------------------------------------------------------- /GCDDemo/GCDDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // GCDDemo 4 | // 5 | // Created by DaiMing on 16/1/13. 6 | // Copyright © 2016年 Starming. 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 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // 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. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // 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. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // 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. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /GCDDemo/GCDDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // GCDDemo 4 | // 5 | // Created by DaiMing on 16/1/13. 6 | // Copyright © 2016年 Starming. 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 | //试着调不同的demo和case 20 | [self dispatchApplyDemo]; 21 | } 22 | 23 | #pragma mark - GCD Demo 24 | //dispatch_set_target_queue 25 | - (void)dispatchSetTargetQueueDemo { 26 | dispatch_queue_t serialQueue = dispatch_queue_create("com.starming.gcddemo.serialqueue", DISPATCH_QUEUE_SERIAL); 27 | dispatch_queue_t firstQueue = dispatch_queue_create("com.starming.gcddemo.firstqueue", DISPATCH_QUEUE_SERIAL); 28 | dispatch_queue_t secondQueue = dispatch_queue_create("com.starming.gcddemo.secondqueue", DISPATCH_QUEUE_CONCURRENT); 29 | 30 | dispatch_set_target_queue(firstQueue, serialQueue); 31 | dispatch_set_target_queue(secondQueue, serialQueue); 32 | 33 | dispatch_async(firstQueue, ^{ 34 | NSLog(@"1"); 35 | [NSThread sleepForTimeInterval:3.f]; 36 | }); 37 | dispatch_async(secondQueue, ^{ 38 | NSLog(@"2"); 39 | [NSThread sleepForTimeInterval:2.f]; 40 | }); 41 | dispatch_async(secondQueue, ^{ 42 | NSLog(@"3"); 43 | [NSThread sleepForTimeInterval:1.f]; 44 | }); 45 | } 46 | 47 | //dispatch_barrier_async 48 | - (void)dispatchBarrierAsyncDemo { 49 | //防止文件读写冲突,可以创建一个串行队列,操作都在这个队列中进行,没有更新数据读用并行,写用串行。 50 | dispatch_queue_t dataQueue = dispatch_queue_create("com.starming.gcddemo.dataqueue", DISPATCH_QUEUE_CONCURRENT); 51 | dispatch_async(dataQueue, ^{ 52 | [NSThread sleepForTimeInterval:2.f]; 53 | NSLog(@"read data 1"); 54 | }); 55 | dispatch_async(dataQueue, ^{ 56 | NSLog(@"read data 2"); 57 | }); 58 | //等待前面的都完成,在执行barrier后面的 59 | dispatch_barrier_async(dataQueue, ^{ 60 | NSLog(@"write data 1"); 61 | [NSThread sleepForTimeInterval:1]; 62 | }); 63 | dispatch_async(dataQueue, ^{ 64 | [NSThread sleepForTimeInterval:1.f]; 65 | NSLog(@"read data 3"); 66 | }); 67 | dispatch_async(dataQueue, ^{ 68 | NSLog(@"read data 4"); 69 | }); 70 | } 71 | 72 | //dispatch_apply 73 | - (void)dispatchApplyDemo { 74 | dispatch_queue_t concurrentQueue = dispatch_queue_create("com.starming.gcddemo.concurrentqueue", DISPATCH_QUEUE_CONCURRENT); 75 | dispatch_apply(10, concurrentQueue, ^(size_t i) { 76 | NSLog(@"%zu",i); 77 | }); 78 | dispatch_async(dispatch_get_main_queue(), ^{ 79 | 80 | }); 81 | NSLog(@"The end"); //这里有个需要注意的是,dispatch_apply这个是会阻塞主线程的。这个log打印会在dispatch_apply都结束后才开始执行,但是使用dispatch_async包一下就不会阻塞了。 82 | } 83 | 84 | //dispatch_apply 85 | - (void)dispatchDealWiththreadWithMaybeExplode:(BOOL)explode { 86 | dispatch_queue_t concurrentQueue = dispatch_queue_create("com.starming.gcddemo.concurrentqueue",DISPATCH_QUEUE_CONCURRENT); 87 | if (explode) { 88 | //有问题的情况,可能会死锁 89 | for (int i = 0; i < 999 ; i++) { 90 | dispatch_async(concurrentQueue, ^{ 91 | NSLog(@"wrong %d",i); 92 | //do something hard 93 | }); 94 | } 95 | } else { 96 | //会优化很多,能够利用GCD管理 97 | dispatch_apply(999, concurrentQueue, ^(size_t i){ 98 | NSLog(@"correct %zu",i); 99 | //do something hard 100 | }); 101 | } 102 | } 103 | 104 | //create dispatch block 105 | - (void)dispatchCreateBlockDemo { 106 | //normal way 107 | dispatch_queue_t concurrentQueue = dispatch_queue_create("com.starming.gcddemo.concurrentqueue",DISPATCH_QUEUE_CONCURRENT); 108 | dispatch_block_t block = dispatch_block_create(0, ^{ 109 | NSLog(@"run block"); 110 | }); 111 | dispatch_async(concurrentQueue, block); 112 | 113 | //QOS way 114 | dispatch_block_t qosBlock = dispatch_block_create_with_qos_class(0, QOS_CLASS_USER_INITIATED, -1, ^{ 115 | NSLog(@"run qos block"); 116 | }); 117 | dispatch_async(concurrentQueue, qosBlock); 118 | } 119 | 120 | //dispatch_block_wait 121 | - (void)dispatchBlockWaitDemo { 122 | dispatch_queue_t serialQueue = dispatch_queue_create("com.starming.gcddemo.serialqueue", DISPATCH_QUEUE_SERIAL); 123 | dispatch_block_t block = dispatch_block_create(0, ^{ 124 | NSLog(@"star"); 125 | [NSThread sleepForTimeInterval:5.f]; 126 | NSLog(@"end"); 127 | }); 128 | dispatch_async(serialQueue, block); 129 | //设置DISPATCH_TIME_FOREVER会一直等到前面任务都完成 130 | dispatch_block_wait(block, DISPATCH_TIME_FOREVER); 131 | NSLog(@"ok, now can go on"); 132 | } 133 | 134 | //dispatch_block_notify 135 | - (void)dispatchBlockNotifyDemo { 136 | dispatch_queue_t serialQueue = dispatch_queue_create("com.starming.gcddemo.serialqueue", DISPATCH_QUEUE_SERIAL); 137 | dispatch_block_t firstBlock = dispatch_block_create(0, ^{ 138 | NSLog(@"first block start"); 139 | [NSThread sleepForTimeInterval:2.f]; 140 | NSLog(@"first block end"); 141 | }); 142 | dispatch_async(serialQueue, firstBlock); 143 | dispatch_block_t secondBlock = dispatch_block_create(0, ^{ 144 | NSLog(@"second block run"); 145 | }); 146 | //first block执行完才在serial queue中执行second block 147 | dispatch_block_notify(firstBlock, serialQueue, secondBlock); 148 | } 149 | 150 | //dispatch_block_cancel(iOS8+) 151 | - (void)dispatchBlockCancelDemo { 152 | dispatch_queue_t serialQueue = dispatch_queue_create("com.starming.gcddemo.serialqueue", DISPATCH_QUEUE_SERIAL); 153 | dispatch_block_t firstBlock = dispatch_block_create(0, ^{ 154 | NSLog(@"first block start"); 155 | [NSThread sleepForTimeInterval:2.f]; 156 | NSLog(@"first block end"); 157 | }); 158 | dispatch_block_t secondBlock = dispatch_block_create(0, ^{ 159 | NSLog(@"second block run"); 160 | }); 161 | dispatch_async(serialQueue, firstBlock); 162 | dispatch_async(serialQueue, secondBlock); 163 | //取消secondBlock 164 | dispatch_block_cancel(secondBlock); 165 | } 166 | 167 | //dispatch_group_wait 168 | - (void)dispatchGroupWaitDemo { 169 | dispatch_queue_t concurrentQueue = dispatch_queue_create("com.starming.gcddemo.concurrentqueue",DISPATCH_QUEUE_CONCURRENT); 170 | dispatch_group_t group = dispatch_group_create(); 171 | //在group中添加队列的block 172 | dispatch_group_async(group, concurrentQueue, ^{ 173 | [NSThread sleepForTimeInterval:2.f]; 174 | NSLog(@"1"); 175 | }); 176 | dispatch_group_async(group, concurrentQueue, ^{ 177 | NSLog(@"2"); 178 | }); 179 | dispatch_group_wait(group, DISPATCH_TIME_FOREVER); 180 | NSLog(@"can continue"); 181 | } 182 | 183 | //dispatch_group_notify 184 | - (void)dispatchGroupNotifyDemo { 185 | dispatch_queue_t concurrentQueue = dispatch_queue_create("com.starming.gcddemo.concurrentqueue",DISPATCH_QUEUE_CONCURRENT); 186 | dispatch_group_t group = dispatch_group_create(); 187 | dispatch_group_async(group, concurrentQueue, ^{ 188 | NSLog(@"1"); 189 | }); 190 | dispatch_group_async(group, concurrentQueue, ^{ 191 | NSLog(@"2"); 192 | }); 193 | dispatch_group_notify(group, dispatch_get_main_queue(), ^{ 194 | NSLog(@"end"); 195 | }); 196 | NSLog(@"can continue"); 197 | } 198 | 199 | //dispatch semaphore 200 | - (void)dispatchSemaphoreDemo { 201 | //创建semaphore 202 | dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); 203 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 204 | NSLog(@"start"); 205 | [NSThread sleepForTimeInterval:1.f]; 206 | NSLog(@"semaphore +1"); 207 | dispatch_semaphore_signal(semaphore); //+1 semaphore 208 | }); 209 | dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); 210 | NSLog(@"continue"); 211 | } 212 | 213 | //dispatch source directory demo 214 | - (void)dispatchSourceDirectoryDemo { 215 | NSURL *directoryURL; // assume this is set to a directory 216 | int const fd = open([[directoryURL path] fileSystemRepresentation], O_EVTONLY); 217 | if (fd < 0) { 218 | char buffer[80]; 219 | strerror_r(errno, buffer, sizeof(buffer)); 220 | NSLog(@"Unable to open \"%@\": %s (%d)", [directoryURL path], buffer, errno); 221 | return; 222 | } 223 | dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_VNODE, fd, 224 | DISPATCH_VNODE_WRITE | DISPATCH_VNODE_DELETE, DISPATCH_TARGET_QUEUE_DEFAULT); 225 | dispatch_source_set_event_handler(source, ^(){ 226 | unsigned long const data = dispatch_source_get_data(source); 227 | if (data & DISPATCH_VNODE_WRITE) { 228 | NSLog(@"The directory changed."); 229 | } 230 | if (data & DISPATCH_VNODE_DELETE) { 231 | NSLog(@"The directory has been deleted."); 232 | } 233 | }); 234 | dispatch_source_set_cancel_handler(source, ^(){ 235 | close(fd); 236 | }); 237 | dispatch_resume(source); 238 | //还要注意需要用DISPATCH_VNODE_DELETE 去检查监视的文件或文件夹是否被删除,如果删除了就停止监听 239 | } 240 | 241 | //dispatch source timer demo 242 | - (void)dispatchSourceTimerDemo { 243 | //NSTimer在主线程的runloop里会在runloop切换其它模式时停止,这时就需要手动在子线程开启一个模式为NSRunLoopCommonModes的runloop,如果不想开启一个新的runloop可以用不跟runloop关联的dispatch source timer 244 | dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER,0, 0, DISPATCH_TARGET_QUEUE_DEFAULT); 245 | dispatch_source_set_event_handler(source, ^(){ 246 | NSLog(@"Time flies."); 247 | }); 248 | dispatch_source_set_timer(source, DISPATCH_TIME_NOW, 5ull * NSEC_PER_SEC,100ull * NSEC_PER_MSEC); 249 | dispatch_resume(source); 250 | } 251 | 252 | //Dead Lock case 1 253 | - (void)deadLockCase1 { 254 | NSLog(@"1"); 255 | //主队列的同步线程,按照FIFO的原则(先入先出),2排在3后面会等3执行完,但因为同步线程,3又要等2执行完,相互等待成为死锁。 256 | dispatch_sync(dispatch_get_main_queue(), ^{ 257 | NSLog(@"2"); 258 | }); 259 | NSLog(@"3"); 260 | } 261 | 262 | //Dead Lock case 2 263 | - (void)deadLockCase2 { 264 | NSLog(@"1"); 265 | //3会等2,因为2在全局并行队列里,不需要等待3,这样2执行完回到主队列,3就开始执行 266 | dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ 267 | NSLog(@"2"); 268 | }); 269 | NSLog(@"3"); 270 | } 271 | 272 | //Dead Lock case 3 273 | - (void)deadLockCase3 { 274 | dispatch_queue_t serialQueue = dispatch_queue_create("com.starming.gcddemo.serialqueue", DISPATCH_QUEUE_SERIAL); 275 | NSLog(@"1"); 276 | dispatch_async(serialQueue, ^{ 277 | NSLog(@"2"); 278 | //串行队列里面同步一个串行队列就会死锁 279 | dispatch_sync(serialQueue, ^{ 280 | NSLog(@"3"); 281 | }); 282 | NSLog(@"4"); 283 | }); 284 | NSLog(@"5"); 285 | } 286 | 287 | //Dead Lock case 4 288 | - (void)deadLockCase4 { 289 | NSLog(@"1"); 290 | dispatch_async(dispatch_get_global_queue(0, 0), ^{ 291 | NSLog(@"2"); 292 | //将同步的串行队列放到另外一个线程就能够解决 293 | dispatch_sync(dispatch_get_main_queue(), ^{ 294 | NSLog(@"3"); 295 | }); 296 | NSLog(@"4"); 297 | }); 298 | NSLog(@"5"); 299 | } 300 | 301 | //Dead Lock case 5 302 | - (void)deadLockCase5 { 303 | dispatch_async(dispatch_get_global_queue(0, 0), ^{ 304 | NSLog(@"1"); 305 | //回到主线程发现死循环后面就没法执行了 306 | dispatch_sync(dispatch_get_main_queue(), ^{ 307 | NSLog(@"2"); 308 | }); 309 | NSLog(@"3"); 310 | }); 311 | NSLog(@"4"); 312 | //死循环 313 | while (1) { 314 | // 315 | } 316 | } 317 | 318 | 319 | @end 320 | -------------------------------------------------------------------------------- /GCDDemo/GCDDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 3E222E721C464A87001A0F3E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E222E711C464A87001A0F3E /* main.m */; }; 11 | 3E222E751C464A87001A0F3E /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E222E741C464A87001A0F3E /* AppDelegate.m */; }; 12 | 3E222E781C464A87001A0F3E /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E222E771C464A87001A0F3E /* ViewController.m */; }; 13 | 3E222E7B1C464A87001A0F3E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3E222E791C464A87001A0F3E /* Main.storyboard */; }; 14 | 3E222E7D1C464A87001A0F3E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3E222E7C1C464A87001A0F3E /* Assets.xcassets */; }; 15 | 3E222E801C464A87001A0F3E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3E222E7E1C464A87001A0F3E /* LaunchScreen.storyboard */; }; 16 | 3E222E8B1C464A87001A0F3E /* GCDDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E222E8A1C464A87001A0F3E /* GCDDemoTests.m */; }; 17 | 3E222E961C464A88001A0F3E /* GCDDemoUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E222E951C464A88001A0F3E /* GCDDemoUITests.m */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXContainerItemProxy section */ 21 | 3E222E871C464A87001A0F3E /* PBXContainerItemProxy */ = { 22 | isa = PBXContainerItemProxy; 23 | containerPortal = 3E222E651C464A87001A0F3E /* Project object */; 24 | proxyType = 1; 25 | remoteGlobalIDString = 3E222E6C1C464A87001A0F3E; 26 | remoteInfo = GCDDemo; 27 | }; 28 | 3E222E921C464A88001A0F3E /* PBXContainerItemProxy */ = { 29 | isa = PBXContainerItemProxy; 30 | containerPortal = 3E222E651C464A87001A0F3E /* Project object */; 31 | proxyType = 1; 32 | remoteGlobalIDString = 3E222E6C1C464A87001A0F3E; 33 | remoteInfo = GCDDemo; 34 | }; 35 | /* End PBXContainerItemProxy section */ 36 | 37 | /* Begin PBXFileReference section */ 38 | 3E222E6D1C464A87001A0F3E /* GCDDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GCDDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 39 | 3E222E711C464A87001A0F3E /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 40 | 3E222E731C464A87001A0F3E /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 41 | 3E222E741C464A87001A0F3E /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 42 | 3E222E761C464A87001A0F3E /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 43 | 3E222E771C464A87001A0F3E /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 44 | 3E222E7A1C464A87001A0F3E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 45 | 3E222E7C1C464A87001A0F3E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 46 | 3E222E7F1C464A87001A0F3E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 47 | 3E222E811C464A87001A0F3E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 48 | 3E222E861C464A87001A0F3E /* GCDDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GCDDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 49 | 3E222E8A1C464A87001A0F3E /* GCDDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GCDDemoTests.m; sourceTree = ""; }; 50 | 3E222E8C1C464A87001A0F3E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 51 | 3E222E911C464A88001A0F3E /* GCDDemoUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GCDDemoUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 52 | 3E222E951C464A88001A0F3E /* GCDDemoUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GCDDemoUITests.m; sourceTree = ""; }; 53 | 3E222E971C464A88001A0F3E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 54 | /* End PBXFileReference section */ 55 | 56 | /* Begin PBXFrameworksBuildPhase section */ 57 | 3E222E6A1C464A87001A0F3E /* Frameworks */ = { 58 | isa = PBXFrameworksBuildPhase; 59 | buildActionMask = 2147483647; 60 | files = ( 61 | ); 62 | runOnlyForDeploymentPostprocessing = 0; 63 | }; 64 | 3E222E831C464A87001A0F3E /* Frameworks */ = { 65 | isa = PBXFrameworksBuildPhase; 66 | buildActionMask = 2147483647; 67 | files = ( 68 | ); 69 | runOnlyForDeploymentPostprocessing = 0; 70 | }; 71 | 3E222E8E1C464A88001A0F3E /* Frameworks */ = { 72 | isa = PBXFrameworksBuildPhase; 73 | buildActionMask = 2147483647; 74 | files = ( 75 | ); 76 | runOnlyForDeploymentPostprocessing = 0; 77 | }; 78 | /* End PBXFrameworksBuildPhase section */ 79 | 80 | /* Begin PBXGroup section */ 81 | 3E222E641C464A87001A0F3E = { 82 | isa = PBXGroup; 83 | children = ( 84 | 3E222E6F1C464A87001A0F3E /* GCDDemo */, 85 | 3E222E891C464A87001A0F3E /* GCDDemoTests */, 86 | 3E222E941C464A88001A0F3E /* GCDDemoUITests */, 87 | 3E222E6E1C464A87001A0F3E /* Products */, 88 | ); 89 | sourceTree = ""; 90 | }; 91 | 3E222E6E1C464A87001A0F3E /* Products */ = { 92 | isa = PBXGroup; 93 | children = ( 94 | 3E222E6D1C464A87001A0F3E /* GCDDemo.app */, 95 | 3E222E861C464A87001A0F3E /* GCDDemoTests.xctest */, 96 | 3E222E911C464A88001A0F3E /* GCDDemoUITests.xctest */, 97 | ); 98 | name = Products; 99 | sourceTree = ""; 100 | }; 101 | 3E222E6F1C464A87001A0F3E /* GCDDemo */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | 3E222E731C464A87001A0F3E /* AppDelegate.h */, 105 | 3E222E741C464A87001A0F3E /* AppDelegate.m */, 106 | 3E222E761C464A87001A0F3E /* ViewController.h */, 107 | 3E222E771C464A87001A0F3E /* ViewController.m */, 108 | 3E222E791C464A87001A0F3E /* Main.storyboard */, 109 | 3E222E7C1C464A87001A0F3E /* Assets.xcassets */, 110 | 3E222E7E1C464A87001A0F3E /* LaunchScreen.storyboard */, 111 | 3E222E811C464A87001A0F3E /* Info.plist */, 112 | 3E222E701C464A87001A0F3E /* Supporting Files */, 113 | ); 114 | path = GCDDemo; 115 | sourceTree = ""; 116 | }; 117 | 3E222E701C464A87001A0F3E /* Supporting Files */ = { 118 | isa = PBXGroup; 119 | children = ( 120 | 3E222E711C464A87001A0F3E /* main.m */, 121 | ); 122 | name = "Supporting Files"; 123 | sourceTree = ""; 124 | }; 125 | 3E222E891C464A87001A0F3E /* GCDDemoTests */ = { 126 | isa = PBXGroup; 127 | children = ( 128 | 3E222E8A1C464A87001A0F3E /* GCDDemoTests.m */, 129 | 3E222E8C1C464A87001A0F3E /* Info.plist */, 130 | ); 131 | path = GCDDemoTests; 132 | sourceTree = ""; 133 | }; 134 | 3E222E941C464A88001A0F3E /* GCDDemoUITests */ = { 135 | isa = PBXGroup; 136 | children = ( 137 | 3E222E951C464A88001A0F3E /* GCDDemoUITests.m */, 138 | 3E222E971C464A88001A0F3E /* Info.plist */, 139 | ); 140 | path = GCDDemoUITests; 141 | sourceTree = ""; 142 | }; 143 | /* End PBXGroup section */ 144 | 145 | /* Begin PBXNativeTarget section */ 146 | 3E222E6C1C464A87001A0F3E /* GCDDemo */ = { 147 | isa = PBXNativeTarget; 148 | buildConfigurationList = 3E222E9A1C464A88001A0F3E /* Build configuration list for PBXNativeTarget "GCDDemo" */; 149 | buildPhases = ( 150 | 3E222E691C464A87001A0F3E /* Sources */, 151 | 3E222E6A1C464A87001A0F3E /* Frameworks */, 152 | 3E222E6B1C464A87001A0F3E /* Resources */, 153 | ); 154 | buildRules = ( 155 | ); 156 | dependencies = ( 157 | ); 158 | name = GCDDemo; 159 | productName = GCDDemo; 160 | productReference = 3E222E6D1C464A87001A0F3E /* GCDDemo.app */; 161 | productType = "com.apple.product-type.application"; 162 | }; 163 | 3E222E851C464A87001A0F3E /* GCDDemoTests */ = { 164 | isa = PBXNativeTarget; 165 | buildConfigurationList = 3E222E9D1C464A88001A0F3E /* Build configuration list for PBXNativeTarget "GCDDemoTests" */; 166 | buildPhases = ( 167 | 3E222E821C464A87001A0F3E /* Sources */, 168 | 3E222E831C464A87001A0F3E /* Frameworks */, 169 | 3E222E841C464A87001A0F3E /* Resources */, 170 | ); 171 | buildRules = ( 172 | ); 173 | dependencies = ( 174 | 3E222E881C464A87001A0F3E /* PBXTargetDependency */, 175 | ); 176 | name = GCDDemoTests; 177 | productName = GCDDemoTests; 178 | productReference = 3E222E861C464A87001A0F3E /* GCDDemoTests.xctest */; 179 | productType = "com.apple.product-type.bundle.unit-test"; 180 | }; 181 | 3E222E901C464A88001A0F3E /* GCDDemoUITests */ = { 182 | isa = PBXNativeTarget; 183 | buildConfigurationList = 3E222EA01C464A88001A0F3E /* Build configuration list for PBXNativeTarget "GCDDemoUITests" */; 184 | buildPhases = ( 185 | 3E222E8D1C464A88001A0F3E /* Sources */, 186 | 3E222E8E1C464A88001A0F3E /* Frameworks */, 187 | 3E222E8F1C464A88001A0F3E /* Resources */, 188 | ); 189 | buildRules = ( 190 | ); 191 | dependencies = ( 192 | 3E222E931C464A88001A0F3E /* PBXTargetDependency */, 193 | ); 194 | name = GCDDemoUITests; 195 | productName = GCDDemoUITests; 196 | productReference = 3E222E911C464A88001A0F3E /* GCDDemoUITests.xctest */; 197 | productType = "com.apple.product-type.bundle.ui-testing"; 198 | }; 199 | /* End PBXNativeTarget section */ 200 | 201 | /* Begin PBXProject section */ 202 | 3E222E651C464A87001A0F3E /* Project object */ = { 203 | isa = PBXProject; 204 | attributes = { 205 | LastUpgradeCheck = 0720; 206 | ORGANIZATIONNAME = Starming; 207 | TargetAttributes = { 208 | 3E222E6C1C464A87001A0F3E = { 209 | CreatedOnToolsVersion = 7.2; 210 | }; 211 | 3E222E851C464A87001A0F3E = { 212 | CreatedOnToolsVersion = 7.2; 213 | TestTargetID = 3E222E6C1C464A87001A0F3E; 214 | }; 215 | 3E222E901C464A88001A0F3E = { 216 | CreatedOnToolsVersion = 7.2; 217 | TestTargetID = 3E222E6C1C464A87001A0F3E; 218 | }; 219 | }; 220 | }; 221 | buildConfigurationList = 3E222E681C464A87001A0F3E /* Build configuration list for PBXProject "GCDDemo" */; 222 | compatibilityVersion = "Xcode 3.2"; 223 | developmentRegion = English; 224 | hasScannedForEncodings = 0; 225 | knownRegions = ( 226 | en, 227 | Base, 228 | ); 229 | mainGroup = 3E222E641C464A87001A0F3E; 230 | productRefGroup = 3E222E6E1C464A87001A0F3E /* Products */; 231 | projectDirPath = ""; 232 | projectRoot = ""; 233 | targets = ( 234 | 3E222E6C1C464A87001A0F3E /* GCDDemo */, 235 | 3E222E851C464A87001A0F3E /* GCDDemoTests */, 236 | 3E222E901C464A88001A0F3E /* GCDDemoUITests */, 237 | ); 238 | }; 239 | /* End PBXProject section */ 240 | 241 | /* Begin PBXResourcesBuildPhase section */ 242 | 3E222E6B1C464A87001A0F3E /* Resources */ = { 243 | isa = PBXResourcesBuildPhase; 244 | buildActionMask = 2147483647; 245 | files = ( 246 | 3E222E801C464A87001A0F3E /* LaunchScreen.storyboard in Resources */, 247 | 3E222E7D1C464A87001A0F3E /* Assets.xcassets in Resources */, 248 | 3E222E7B1C464A87001A0F3E /* Main.storyboard in Resources */, 249 | ); 250 | runOnlyForDeploymentPostprocessing = 0; 251 | }; 252 | 3E222E841C464A87001A0F3E /* Resources */ = { 253 | isa = PBXResourcesBuildPhase; 254 | buildActionMask = 2147483647; 255 | files = ( 256 | ); 257 | runOnlyForDeploymentPostprocessing = 0; 258 | }; 259 | 3E222E8F1C464A88001A0F3E /* Resources */ = { 260 | isa = PBXResourcesBuildPhase; 261 | buildActionMask = 2147483647; 262 | files = ( 263 | ); 264 | runOnlyForDeploymentPostprocessing = 0; 265 | }; 266 | /* End PBXResourcesBuildPhase section */ 267 | 268 | /* Begin PBXSourcesBuildPhase section */ 269 | 3E222E691C464A87001A0F3E /* Sources */ = { 270 | isa = PBXSourcesBuildPhase; 271 | buildActionMask = 2147483647; 272 | files = ( 273 | 3E222E781C464A87001A0F3E /* ViewController.m in Sources */, 274 | 3E222E751C464A87001A0F3E /* AppDelegate.m in Sources */, 275 | 3E222E721C464A87001A0F3E /* main.m in Sources */, 276 | ); 277 | runOnlyForDeploymentPostprocessing = 0; 278 | }; 279 | 3E222E821C464A87001A0F3E /* Sources */ = { 280 | isa = PBXSourcesBuildPhase; 281 | buildActionMask = 2147483647; 282 | files = ( 283 | 3E222E8B1C464A87001A0F3E /* GCDDemoTests.m in Sources */, 284 | ); 285 | runOnlyForDeploymentPostprocessing = 0; 286 | }; 287 | 3E222E8D1C464A88001A0F3E /* Sources */ = { 288 | isa = PBXSourcesBuildPhase; 289 | buildActionMask = 2147483647; 290 | files = ( 291 | 3E222E961C464A88001A0F3E /* GCDDemoUITests.m in Sources */, 292 | ); 293 | runOnlyForDeploymentPostprocessing = 0; 294 | }; 295 | /* End PBXSourcesBuildPhase section */ 296 | 297 | /* Begin PBXTargetDependency section */ 298 | 3E222E881C464A87001A0F3E /* PBXTargetDependency */ = { 299 | isa = PBXTargetDependency; 300 | target = 3E222E6C1C464A87001A0F3E /* GCDDemo */; 301 | targetProxy = 3E222E871C464A87001A0F3E /* PBXContainerItemProxy */; 302 | }; 303 | 3E222E931C464A88001A0F3E /* PBXTargetDependency */ = { 304 | isa = PBXTargetDependency; 305 | target = 3E222E6C1C464A87001A0F3E /* GCDDemo */; 306 | targetProxy = 3E222E921C464A88001A0F3E /* PBXContainerItemProxy */; 307 | }; 308 | /* End PBXTargetDependency section */ 309 | 310 | /* Begin PBXVariantGroup section */ 311 | 3E222E791C464A87001A0F3E /* Main.storyboard */ = { 312 | isa = PBXVariantGroup; 313 | children = ( 314 | 3E222E7A1C464A87001A0F3E /* Base */, 315 | ); 316 | name = Main.storyboard; 317 | sourceTree = ""; 318 | }; 319 | 3E222E7E1C464A87001A0F3E /* LaunchScreen.storyboard */ = { 320 | isa = PBXVariantGroup; 321 | children = ( 322 | 3E222E7F1C464A87001A0F3E /* Base */, 323 | ); 324 | name = LaunchScreen.storyboard; 325 | sourceTree = ""; 326 | }; 327 | /* End PBXVariantGroup section */ 328 | 329 | /* Begin XCBuildConfiguration section */ 330 | 3E222E981C464A88001A0F3E /* Debug */ = { 331 | isa = XCBuildConfiguration; 332 | buildSettings = { 333 | ALWAYS_SEARCH_USER_PATHS = NO; 334 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 335 | CLANG_CXX_LIBRARY = "libc++"; 336 | CLANG_ENABLE_MODULES = YES; 337 | CLANG_ENABLE_OBJC_ARC = YES; 338 | CLANG_WARN_BOOL_CONVERSION = YES; 339 | CLANG_WARN_CONSTANT_CONVERSION = YES; 340 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 341 | CLANG_WARN_EMPTY_BODY = YES; 342 | CLANG_WARN_ENUM_CONVERSION = YES; 343 | CLANG_WARN_INT_CONVERSION = YES; 344 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 345 | CLANG_WARN_UNREACHABLE_CODE = YES; 346 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 347 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 348 | COPY_PHASE_STRIP = NO; 349 | DEBUG_INFORMATION_FORMAT = dwarf; 350 | ENABLE_STRICT_OBJC_MSGSEND = YES; 351 | ENABLE_TESTABILITY = YES; 352 | GCC_C_LANGUAGE_STANDARD = gnu99; 353 | GCC_DYNAMIC_NO_PIC = NO; 354 | GCC_NO_COMMON_BLOCKS = YES; 355 | GCC_OPTIMIZATION_LEVEL = 0; 356 | GCC_PREPROCESSOR_DEFINITIONS = ( 357 | "DEBUG=1", 358 | "$(inherited)", 359 | ); 360 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 361 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 362 | GCC_WARN_UNDECLARED_SELECTOR = YES; 363 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 364 | GCC_WARN_UNUSED_FUNCTION = YES; 365 | GCC_WARN_UNUSED_VARIABLE = YES; 366 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 367 | MTL_ENABLE_DEBUG_INFO = YES; 368 | ONLY_ACTIVE_ARCH = YES; 369 | SDKROOT = iphoneos; 370 | }; 371 | name = Debug; 372 | }; 373 | 3E222E991C464A88001A0F3E /* Release */ = { 374 | isa = XCBuildConfiguration; 375 | buildSettings = { 376 | ALWAYS_SEARCH_USER_PATHS = NO; 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_EMPTY_BODY = YES; 385 | CLANG_WARN_ENUM_CONVERSION = YES; 386 | CLANG_WARN_INT_CONVERSION = YES; 387 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 388 | CLANG_WARN_UNREACHABLE_CODE = YES; 389 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 390 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 391 | COPY_PHASE_STRIP = NO; 392 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 393 | ENABLE_NS_ASSERTIONS = NO; 394 | ENABLE_STRICT_OBJC_MSGSEND = YES; 395 | GCC_C_LANGUAGE_STANDARD = gnu99; 396 | GCC_NO_COMMON_BLOCKS = YES; 397 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 398 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 399 | GCC_WARN_UNDECLARED_SELECTOR = YES; 400 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 401 | GCC_WARN_UNUSED_FUNCTION = YES; 402 | GCC_WARN_UNUSED_VARIABLE = YES; 403 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 404 | MTL_ENABLE_DEBUG_INFO = NO; 405 | SDKROOT = iphoneos; 406 | VALIDATE_PRODUCT = YES; 407 | }; 408 | name = Release; 409 | }; 410 | 3E222E9B1C464A88001A0F3E /* Debug */ = { 411 | isa = XCBuildConfiguration; 412 | buildSettings = { 413 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 414 | INFOPLIST_FILE = GCDDemo/Info.plist; 415 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 416 | PRODUCT_BUNDLE_IDENTIFIER = com.starming.GCDDemo; 417 | PRODUCT_NAME = "$(TARGET_NAME)"; 418 | }; 419 | name = Debug; 420 | }; 421 | 3E222E9C1C464A88001A0F3E /* Release */ = { 422 | isa = XCBuildConfiguration; 423 | buildSettings = { 424 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 425 | INFOPLIST_FILE = GCDDemo/Info.plist; 426 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 427 | PRODUCT_BUNDLE_IDENTIFIER = com.starming.GCDDemo; 428 | PRODUCT_NAME = "$(TARGET_NAME)"; 429 | }; 430 | name = Release; 431 | }; 432 | 3E222E9E1C464A88001A0F3E /* Debug */ = { 433 | isa = XCBuildConfiguration; 434 | buildSettings = { 435 | BUNDLE_LOADER = "$(TEST_HOST)"; 436 | INFOPLIST_FILE = GCDDemoTests/Info.plist; 437 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 438 | PRODUCT_BUNDLE_IDENTIFIER = com.starming.GCDDemoTests; 439 | PRODUCT_NAME = "$(TARGET_NAME)"; 440 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/GCDDemo.app/GCDDemo"; 441 | }; 442 | name = Debug; 443 | }; 444 | 3E222E9F1C464A88001A0F3E /* Release */ = { 445 | isa = XCBuildConfiguration; 446 | buildSettings = { 447 | BUNDLE_LOADER = "$(TEST_HOST)"; 448 | INFOPLIST_FILE = GCDDemoTests/Info.plist; 449 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 450 | PRODUCT_BUNDLE_IDENTIFIER = com.starming.GCDDemoTests; 451 | PRODUCT_NAME = "$(TARGET_NAME)"; 452 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/GCDDemo.app/GCDDemo"; 453 | }; 454 | name = Release; 455 | }; 456 | 3E222EA11C464A88001A0F3E /* Debug */ = { 457 | isa = XCBuildConfiguration; 458 | buildSettings = { 459 | INFOPLIST_FILE = GCDDemoUITests/Info.plist; 460 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 461 | PRODUCT_BUNDLE_IDENTIFIER = com.starming.GCDDemoUITests; 462 | PRODUCT_NAME = "$(TARGET_NAME)"; 463 | TEST_TARGET_NAME = GCDDemo; 464 | USES_XCTRUNNER = YES; 465 | }; 466 | name = Debug; 467 | }; 468 | 3E222EA21C464A88001A0F3E /* Release */ = { 469 | isa = XCBuildConfiguration; 470 | buildSettings = { 471 | INFOPLIST_FILE = GCDDemoUITests/Info.plist; 472 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 473 | PRODUCT_BUNDLE_IDENTIFIER = com.starming.GCDDemoUITests; 474 | PRODUCT_NAME = "$(TARGET_NAME)"; 475 | TEST_TARGET_NAME = GCDDemo; 476 | USES_XCTRUNNER = YES; 477 | }; 478 | name = Release; 479 | }; 480 | /* End XCBuildConfiguration section */ 481 | 482 | /* Begin XCConfigurationList section */ 483 | 3E222E681C464A87001A0F3E /* Build configuration list for PBXProject "GCDDemo" */ = { 484 | isa = XCConfigurationList; 485 | buildConfigurations = ( 486 | 3E222E981C464A88001A0F3E /* Debug */, 487 | 3E222E991C464A88001A0F3E /* Release */, 488 | ); 489 | defaultConfigurationIsVisible = 0; 490 | defaultConfigurationName = Release; 491 | }; 492 | 3E222E9A1C464A88001A0F3E /* Build configuration list for PBXNativeTarget "GCDDemo" */ = { 493 | isa = XCConfigurationList; 494 | buildConfigurations = ( 495 | 3E222E9B1C464A88001A0F3E /* Debug */, 496 | 3E222E9C1C464A88001A0F3E /* Release */, 497 | ); 498 | defaultConfigurationIsVisible = 0; 499 | }; 500 | 3E222E9D1C464A88001A0F3E /* Build configuration list for PBXNativeTarget "GCDDemoTests" */ = { 501 | isa = XCConfigurationList; 502 | buildConfigurations = ( 503 | 3E222E9E1C464A88001A0F3E /* Debug */, 504 | 3E222E9F1C464A88001A0F3E /* Release */, 505 | ); 506 | defaultConfigurationIsVisible = 0; 507 | }; 508 | 3E222EA01C464A88001A0F3E /* Build configuration list for PBXNativeTarget "GCDDemoUITests" */ = { 509 | isa = XCConfigurationList; 510 | buildConfigurations = ( 511 | 3E222EA11C464A88001A0F3E /* Debug */, 512 | 3E222EA21C464A88001A0F3E /* Release */, 513 | ); 514 | defaultConfigurationIsVisible = 0; 515 | }; 516 | /* End XCConfigurationList section */ 517 | }; 518 | rootObject = 3E222E651C464A87001A0F3E /* Project object */; 519 | } 520 | --------------------------------------------------------------------------------