IOS第一天多线程-04GCD通信

时间:2022-05-27 09:30:45

****

#define HMGlobalQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
#define HMMainQueue dispatch_get_main_queue() #import "HMViewController.h" @interface HMViewController ()
@property (weak, nonatomic) IBOutlet UIButton *button; @property (weak, nonatomic) IBOutlet UIImageView *newImageView;
@end @implementation HMViewController - (void)viewDidLoad
{
[super viewDidLoad]; [self newImageView]; // NSObject *obj = [NSObject new];
//
// [[NSObject alloc] init]; // Do any additional setup after loading the view, typically from a nib.
} - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
dispatch_async(HMGlobalQueue, ^{
NSLog(@"donwload---%@", [NSThread currentThread]);
// 1.子线程下载图片
NSURL *url = [NSURL URLWithString:@"http://d.hiphotos.baidu.com/image/pic/item/37d3d539b6003af3290eaf5d362ac65c1038b652.jpg"];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data]; // 2.回到主线程设置图片
dispatch_async(HMMainQueue, ^{
NSLog(@"setting---%@ %@", [NSThread currentThread], image);
[self.button setImage:image forState:UIControlStateNormal];
});
});
} @end

IOS第一天多线程-04GCD通信的更多相关文章

  1. IOS第一天多线程-03线程间通信

    **** #import "HMViewController.h" @interface HMViewController () @property (weak, nonatomi ...

  2. IOS第一天多线程-05GCD队列的使用

    ************** // // HMViewController.m // 08-GCD02-队列的使用(了解) // // Created by apple on 14-9-15. // ...

  3. IOS第一天多线程-02NSThread基本使用

    **** #import "HMViewController.h" @interface HMViewController () @end @implementation HMVi ...

  4. IOS第一天多线程-01pthread

    *** #import "HMViewController.h" #import <pthread.h> @interface HMViewController () ...

  5. iOS开发-多线程编程技术(Thread、Cocoa operations、GCD)

    简介 在软件开发中,多线程编程技术被广泛应用,相信多线程任务对我们来说已经不再陌生了.有了多线程技术,我们可以同做多个事情,而不是一个一个任务地进行.比如:前端和后台作交互.大任务(需要耗费一定的时间 ...

  6. ios开发之多线程---GCD

    一:基本概念 1:进程:正在运行的程序为进程. 2:线程:每个进程要想执行任务必须得有线程,进程中任务的执行都是在线程中. 3:线程的串行:一条线程里任务的执行都是串行的,假如有一个进程开辟了一条线程 ...

  7. 大厂常问iOS面试题--多线程篇

    1.进程与线程 进程: 1.进程是一个具有一定独立功能的程序关于某次数据集合的一次运行活动,它是操作系统分配资源的基本单元. 2.进程是指在系统中正在运行的一个应用程序,就是一段程序的执行过程,我们可 ...

  8. iOS开发之多线程技术

    本篇争取一篇讲清讲透,依然将通过四大方面清晰的对iOS开发中多线程的用法进行详尽的讲解: 一.什么是多线程 1)多线程执行原理 2)线程与进程 3)多线程的优缺点 二.我们为什么要用多线程编程技术 三 ...

  9. IOS编程之多线程

    IOS编程之多线程 目录 概述——对多线程的理解 IOS中实现多线程的三种方式 NSThread 线程创建 线程的同步与锁 线程间的交互 线程的操作方法 NSOperation and NSOpera ...

随机推荐

  1. background-image和img的区别

    background-img的时候外边的div必须有宽和高.并且你只能决定图片位于你div的位置不能拉伸图片,或者改变图片的宽高.但是background-image是可以重复的,所以只要你的图片不是 ...

  2. UltraEdit中使用正则表达式

    正则表达式 (UltraEdit Syntax): % 匹配行首 - 表明要搜索的字符串一定在行首. $ 匹配行尾 - 表明要搜索的字符串一定在行尾 ? 匹配除换行符外的任一单个字符. * 匹配任意个 ...

  3. FxCop

    下载地址:http://www.microsoft.com/en-us/download/details.aspx?id=8279 FxCop是一个代码分析工具,和StyleCop(代码规范)一起配合 ...

  4. Top WAF

    http://blog.csdn.net/force_eagle/article/details/9396087

  5. 一天一个类 --- StringTokenizer

    这是一个将字符串按照指定的delimiters(分隔符)进行分割的类. 首先看看他的构造函数: public StringTokenizer(String str, String delim, boo ...

  6. python学习&equals;&equals;&equals;从键盘输入一些字符,逐个把它们写到磁盘文件上,直到输入一个 &num; 为止。

    #!/usr/bin/python # -*- coding: UTF-8 -*- if __name__ == '__main__': from sys import stdout filename ...

  7. ABP中的拦截器之EntityHistoryInterceptor

    今天我们接着之前的系列接着来写另外一种拦截器EntityHistoryInterceptor,这个拦截器到底是做什么的呢?这个从字面上理解是实体历史?这个到底是什么意思?带着这个问题我们来一步步去分析 ...

  8. L256 翻译

    Should work be placed among the causes of happiness or be regarded as a burden? Much work isexceedin ...

  9. ElasticSearch 2 &lpar;12&rpar; - Shard数调优(ElasticSearch性能)

    ElasticSearch 2 (12) - Shard数调优(ElasticSearch性能) 摘要 当创建一个索引的时候,我们经常会面对一个问题:要为索引分配多少个shard?多少个replica ...

  10. 抽象语法符号ASN&period;1(Abstract Syntax Notation One)

      一.ASN.1 (Abstract Syntax Notation One) ASN.1包括两部分:数据描述语言(ISO 8824)和数据编码规则(ISO 8825).ASN.1的数据描述语言允许 ...