-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewController.m
More file actions
109 lines (70 loc) · 2.22 KB
/
ViewController.m
File metadata and controls
109 lines (70 loc) · 2.22 KB
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
29
30
31
32
33
34
35
36
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//
// ViewController.m
// iOSNoteStudy
//
// Created by Lj on 2018/4/17.
// Copyright © 2018年 lj. All rights reserved.
//
#import "ViewController.h"
#import <objc/runtime.h>
#import <FMDB/FMDB.h>
#import "CustomNotificationCenter.h"
@class FootView;
@interface ViewController ()
@property (nonatomic, strong) UILabel *nameLabel;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// NSOperationQueue *dad = [NSOperationQueue add]
__block NSInteger number = 0;
dispatch_group_t group = dispatch_group_create();
// A耗时操作
dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
sleep(3);
number += 222;
});
// B网络请求
dispatch_group_enter(group);
[self sendRequestWithCompletion:^(id response) {
number += [response integerValue];
dispatch_group_leave(group);
}];
// C网络请求
dispatch_group_enter(group);
[self sendRequestWithCompletion:^(id response) {
number += [response integerValue];
dispatch_group_leave(group);
}];
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
NSLog(@"%zd", number);
});
[self runtime];
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dataScuucess) name:@"123455" object:nil];
// [[CustomNotice share] addObserver:self selector:@selector(dataScuucess) name:@"dataScuucess"];
}
- (void)dataScuucess {
NSLog(@"123456");
}
- (void)sendRequestWithCompletion:(void (^)(id response))completion {
// 模拟一个网络请求
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
sleep(2);
dispatch_async(dispatch_get_main_queue(), ^{
if (completion) {
completion(@111);
}
});
});
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)runtime {
}
@end
@implementation ClassName
@end