-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathblock.html
131 lines (108 loc) · 2.89 KB
/
block.html
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<html>
<head>
<title>How Do I Declare A Block in Objective-C?</title>
<style>
body {
background-color: #042029;
color: #83948F;
font-family: Lucida Grande, sans-serif;
font-size: 20px;
padding: 40px;
padding-bottom: 0;
}
strong {
color: #0088D9;
}
h1 {
font-size: 40px;
margin-bottom: 1.5em;
text-align: center;
}
h2 {
font-weight: normal;
}
.return {
color: #00A69A;
}
.name {
color: #BC8800;
}
.parameter-types, .parameters {
color: #7C9F00;
}
code {
display: block;
font-family: Monaco, Menlo;
font-size: 20px;
margin-bottom: 3em;
margin-left: 40px;
margin-top: 1.5em;
}
footer {
font-size: 12px;
margin-top: 200px;
opacity: 0.4;
text-align: right;
}
footer a {
color: #0088D9;
text-decoration: none;
}
</style>
<style media='print'>
body {
background-color: #FFFFFF;
font-size: 16px;
padding: 20px;
}
h1 {
font-size: 28px;
margin-bottom: 1em;
}
code {
font-size: 16px;
margin-bottom: 2em;
margin-left: 20px;
}
footer {
font-size: 10px;
margin-top: 40px;
}
</style>
</head>
<body>
<h1>How Do I Declare A Block in Objective-C?</h1>
<div>
<h2>As a <strong>local variable</strong>:</h2>
<code>
<span class='return'>returnType</span> (^<span class='name'>blockName</span>)(<span class='parameter-types'>parameterTypes</span>) = ^<span class='return'>returnType</span>(<span class='parameters'>parameters</span>) {...};
</code>
</div>
<div>
<h2>As a <strong>property</strong>:</h2>
<code>
@property (nonatomic, copy) <span class='return'>returnType</span> (^<span class='name'>blockName</span>)(<span class='parameter-types'>parameterTypes</span>);
</code>
</div>
<div>
<h2>As a <strong>method parameter</strong>:</h2>
<code>
- (void)someMethodThatTakesABlock:(<span class='return'>returnType</span> (^)(<span class='parameter-types'>parameterTypes</span>))<span class='name'>blockName</span> {...}
</code>
</div>
<div>
<h2>As an <strong>argument to a method call</strong>:</h2>
<code>
[someObject someMethodThatTakesABlock: ^<span class='return'>returnType</span> (<span class='parameters'>parameters</span>) {...}];
</code>
</div>
<div>
<h2>As a <strong>typedef</strong>:</h2>
<code>
typedef <span class='return'>returnType</span> (^<span class='name'>TypeName</span>)(<span class='parameter-types'>parameterTypes</span>);<br/>
<span class='name'>TypeName</span> blockName = ^(<span class='parameters'>parameters</span>) {...}
</code>
</div>
<footer>By <a href="http://lazerwalker.com">Mike Walker</a>, who has a very bad memory for this sort of thing.</footer>
</body>
</html>