{"action":"created","issue":{"url":"https://api.github.com/repos/bingoogolapple/bingoogolapple.github.io/issues/56","labels_url":"https://api.github.com/repos/bingoogolapple/bingoogolapple.github.io/issues/56/labels{/name}","comments_url":"https://api.github.com/repos/bingoogolapple/bingoogolapple.github.io/issues/56/comments","events_url":"https://api.github.com/repos/bingoogolapple/bingoogolapple.github.io/issues/56/events","html_url":"https://github.com/bingoogolapple/bingoogolapple.github.io/issues/56","id":67729972,"number":56,"title":"GCD","user":{"login":"bingoogolapple","id":8949716,"avatar_url":"https://avatars.githubusercontent.com/u/8949716?v=3","gravatar_id":"","url":"https://api.github.com/users/bingoogolapple","html_url":"https://github.com/bingoogolapple","followers_url":"https://api.github.com/users/bingoogolapple/followers","following_url":"https://api.github.com/users/bingoogolapple/following{/other_user}","gists_url":"https://api.github.com/users/bingoogolapple/gists{/gist_id}","starred_url":"https://api.github.com/users/bingoogolapple/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bingoogolapple/subscriptions","organizations_url":"https://api.github.com/users/bingoogolapple/orgs","repos_url":"https://api.github.com/users/bingoogolapple/repos","events_url":"https://api.github.com/users/bingoogolapple/events{/privacy}","received_events_url":"https://api.github.com/users/bingoogolapple/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/bingoogolapple/bingoogolapple.github.io/labels/iOS","name":"iOS","color":"88FF88"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-11T04:02:59Z","updated_at":"2015-04-11T07:30:32Z","closed_at":null,"body":"```Objective-C\r\n/**\r\n *  async -- 并发队列（最常用）\r\n *  会不会创建线程：会，一般同时开多条\r\n *  任务的执行方式：并发执行\r\n */\r\n- (void)asyncGlobalQueue\r\n{\r\n    // 获得全局的并发队列\r\n    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);\r\n    \r\n    // 将 任务 添加 全局队列 中去 异步 执行\r\n    dispatch_async(queue, ^{\r\n        NSLog(@\"-----下载图片1---%@\", [NSThread currentThread]);\r\n    });\r\n    dispatch_async(queue, ^{\r\n        NSLog(@\"-----下载图片2---%@\", [NSThread currentThread]);\r\n    });\r\n    dispatch_async(queue, ^{\r\n        NSLog(@\"-----下载图片3---%@\", [NSThread currentThread]);\r\n    });\r\n    dispatch_async(queue, ^{\r\n        NSLog(@\"-----下载图片4---%@\", [NSThread currentThread]);\r\n    });\r\n    dispatch_async(queue, ^{\r\n        NSLog(@\"-----下载图片5---%@\", [NSThread currentThread]);\r\n    });\r\n}\r\n\r\n/**\r\n *  async -- 串行队列（有时候用）\r\n *  会不会创建线程：会，一般只开1条线程\r\n *  任务的执行方式：串行执行（一个任务执行完毕后再执行下一个任务）\r\n */\r\n- (void)asyncSerialQueue\r\n{\r\n    // 1.创建一个串行队列\r\n    dispatch_queue_t queue = dispatch_queue_create(\"cn.heima.queue\", NULL);\r\n    \r\n    // 2.将任务添加到串行队列中 异步 执行\r\n    dispatch_async(queue, ^{\r\n        NSLog(@\"-----下载图片1---%@\", [NSThread currentThread]);\r\n    });\r\n    dispatch_async(queue, ^{\r\n        NSLog(@\"-----下载图片2---%@\", [NSThread currentThread]);\r\n    });\r\n    dispatch_async(queue, ^{\r\n        NSLog(@\"-----下载图片3---%@\", [NSThread currentThread]);\r\n    });\r\n    dispatch_async(queue, ^{\r\n        NSLog(@\"-----下载图片4---%@\", [NSThread currentThread]);\r\n    });\r\n    dispatch_async(queue, ^{\r\n        NSLog(@\"-----下载图片5---%@\", [NSThread currentThread]);\r\n    });\r\n    \r\n    // 3.非ARC，需要释放创建的队列\r\n//    dispatch_release(queue);\r\n}\r\n\r\n/**\r\n *  async -- 主队列(很常用)\r\n */\r\n- (void)asyncMainQueue\r\n{\r\n    // 1.主队列(添加到主队列中的任务，都会自动放到主线程中去执行)\r\n    dispatch_queue_t queue = dispatch_get_main_queue();\r\n    \r\n    // 2.添加 任务 到主队列中 异步 执行\r\n    dispatch_async(queue, ^{\r\n        NSLog(@\"-----下载图片1---%@\", [NSThread currentThread]);\r\n    });\r\n    dispatch_async(queue, ^{\r\n        NSLog(@\"-----下载图片2---%@\", [NSThread currentThread]);\r\n    });\r\n    dispatch_async(queue, ^{\r\n        NSLog(@\"-----下载图片3---%@\", [NSThread currentThread]);\r\n    });\r\n    dispatch_async(queue, ^{\r\n        NSLog(@\"-----下载图片4---%@\", [NSThread currentThread]);\r\n    });\r\n    dispatch_async(queue, ^{\r\n        NSLog(@\"-----下载图片5---%@\", [NSThread currentThread]);\r\n    });\r\n}\r\n\r\n\r\n/*\r\n 凡是函数名中带有create\\copy\\new\\retain等字眼, 都应该在不需要使用这个数据的时候进行release\r\n GCD的数据类型在ARC环境下不需要再做release\r\n CF(Core Foundation)的数据类型在ARC\\MRC环境下都需要再做release\r\n */\r\n```\r\n\r\nOC中对象的属性不能以new开头"},"comment":{"url":"https://api.github.com/repos/bingoogolapple/bingoogolapple.github.io/issues/comments/91784147","html_url":"https://github.com/bingoogolapple/bingoogolapple.github.io/issues/56#issuecomment-91784147","issue_url":"https://api.github.com/repos/bingoogolapple/bingoogolapple.github.io/issues/56","id":91784147,"user":{"login":"bingoogolapple","id":8949716,"avatar_url":"https://avatars.githubusercontent.com/u/8949716?v=3","gravatar_id":"","url":"https://api.github.com/users/bingoogolapple","html_url":"https://github.com/bingoogolapple","followers_url":"https://api.github.com/users/bingoogolapple/followers","following_url":"https://api.github.com/users/bingoogolapple/following{/other_user}","gists_url":"https://api.github.com/users/bingoogolapple/gists{/gist_id}","starred_url":"https://api.github.com/users/bingoogolapple/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bingoogolapple/subscriptions","organizations_url":"https://api.github.com/users/bingoogolapple/orgs","repos_url":"https://api.github.com/users/bingoogolapple/repos","events_url":"https://api.github.com/users/bingoogolapple/events{/privacy}","received_events_url":"https://api.github.com/users/bingoogolapple/received_events","type":"User","site_admin":false},"created_at":"2015-04-11T07:30:32Z","updated_at":"2015-04-11T07:30:32Z","body":"### 线程间通信\r\n\r\n```Objective-C\r\n- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event\r\n{\r\n    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{\r\n        NSLog(@\"donwload---%@\", [NSThread currentThread]);\r\n        // 1.子线程下载图片\r\n        NSURL *url = [NSURL URLWithString:@\"http://d.hiphotos.baidu.com/image/pic/item/37d3d539b6003af3290eaf5d362ac65c1038b652.jpg\"];\r\n        NSData *data = [NSData dataWithContentsOfURL:url];\r\n        UIImage *image = [UIImage imageWithData:data];\r\n        \r\n        // 2.回到主线程设置图片\r\n        dispatch_async(dispatch_get_main_queue(), ^{\r\n            NSLog(@\"setting---%@ %@\", [NSThread currentThread], image);\r\n            [self.button setImage:image forState:UIControlStateNormal];\r\n        });\r\n    });\r\n}\r\n```"}}