iOS multithreaded development small Demo7 GCD queue Group

Source: Internet
Author: User

dyfviewcontroller.m//623-08-Queue group////Created by Dyf on 14-6-23.//Copyright (c) 2014 ___fullusername___. All rights reserved.//#import "DYFViewController.h" @interface Dyfviewcontroller () @property (weak, nonatomic) Iboutlet Uiimageview *iconv1; @property (weak, nonatomic) Iboutlet Uiimageview *iconv2; @property (weak, nonatomic) Iboutlet Uiimageview *bigiconv; @end @implementation dyfviewcontroller-(void) viewdidload{[Super viewdidload];//do any addition Al Setup after loading the view, typically from a nib.}    -(void) didreceivememorywarning{[Super didreceivememorywarning]; Dispose of any resources the can be recreated.}    -(void) Touchesbegan: (Nsset *) touches withevent: (uievent *) event{NSLog (@ "%@", [Nsthread CurrentThread]);    dispatch_group_t group = Dispatch_group_create ();        dispatch_queue_t queue = Dispatch_get_global_queue (Dispatch_queue_priority_default, 0);    __block UIImage *icon1 = nil; Dispatch_group_async (group, queue, ^{NSLog (@ "%@", [NSTHread CurrentThread]);            Icon1 = [Self imagewithurl:@ "http://image.cache.xiu8.com/live/125/125/997729.jpg"];    });    __block UIImage *icon2 = nil;        Dispatch_group_async (group, queue, ^{NSLog (@ "%@", [Nsthread CurrentThread]); Icon2 = [Self imagewithurl:@] Http://news.baidu.com/z/resource/r/image/2014-06-22/b2a9cfc88b7a56cfa59b8d09208fa1    Fb.jpg "];        });        Dispatch_group_notify (Group, Dispatch_get_main_queue (), ^{NSLog (@ "%@", [Nsthread CurrentThread]);        Self.iconV1.image = Icon1;                Self.iconV2.image = Icon2;        Uigraphicsbeginimagecontextwithoptions (Cgsizemake (max.), NO, 0);        [Icon1 drawinrect:cgrectmake (0, 0, 100, 100)];        [Icon2 drawinrect:cgrectmake (100, 0, 100, 100)];                Self.bigIconV.image = Uigraphicsgetimagefromcurrentimagecontext ();    Uigraphicsendimagecontext (); });} -(UIImage *) Imagewithurl: (NSString *) iconpath{NSLog (@ "%@", [Nsthread CurrentthreAD]);    Nsurl *url = [Nsurl Urlwithstring:iconpath];    NSData *data = [NSData Datawithcontentsofurl:url]; return [UIImage Imagewithdata:data];} @end

Summary:

------------Queue Group------

1. There is a need

• First: Perform 2 time-consuming operations asynchronously, respectively

• Second: Wait 2 after each asynchronous operation is completed, then go back to the main thread to perform the operation

2. If you want to achieve these requirements quickly and efficiently, consider using queue groups

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.