This repository was archived by the owner on Jan 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappendix.html
470 lines (362 loc) · 21.9 KB
/
appendix.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8">
<!-- seems to be needed -->
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
<title>Appendix – Objective-C Runtime in Pictures</title>
<meta name="description" content="Syntax topic
">
<meta name="keywords" content="">
<!-- Twitter Cards -->
<meta name="twitter:title" content="Appendix">
<meta name="twitter:description" content="Syntax topic
">
<meta name="twitter:site" content="@mulle_nat">
<meta name="twitter:creator" content="@mulle_nat">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="/objc-runtime-in-pictures/images/default-thumb.png">
<!-- Open Graph -->
<meta property="og:locale" content="en_US">
<meta property="og:type" content="article">
<meta property="og:title" content="Appendix">
<meta property="og:description" content="Syntax topic
">
<meta property="og:url" content="https://www.mulle-kybernetik.com/appendix.html">
<meta property="og:site_name" content="Objective-C Runtime in Pictures">
<link href="/objc-runtime-in-pictures/atom.xml" type="application/atom+xml" rel="alternate" title="Objective-C Runtime in Pictures Feed">
<link href="/objc-runtime-in-pictures/index.rdf" type="application/rss+xml" rel="alternate" title="Objective-C Runtime in Pictures Feed">
<link rel="canonical" href="https://www.mulle-kybernetik.com/appendix.html">
<!-- Mobile Specific Metas
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSS
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/skeleton.css">
<!-- Code Color
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="stylesheet" href="css/monokai.css">
<!-- Site custom css -->
<link rel="stylesheet" href="css/custom.css">
<!-- local FONT
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="stylesheet" href="css/junction.css">
<!-- Favicon
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="icon" type="image/svg" href="images/favicon.svg">
<!-- This tag allows for activation of ClearType in Mobile IE for smoothing fonts.-->
<meta http-equiv="cleartype" content="on">
<!-- http://t.co/dKP3o1e -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- For all browsers -->
</head>
<body class="post">
<div class="container">
<div class="row">
<div id="post-first" class="four columns">
<div class="sideline">
<div class="bio">
<div class="bio-photo-container" style="display: inline-block">
<img src="/objc-runtime-in-pictures/images/dog-pic.jpg" class="bio-photo" alt="Nat! bio photo">
</div>
<div style="display: inline-block; padding-left: 8px">
<h4>Nat!</h4>
<p>Senior Mull</p>
</div>
<div class="author-social"><a href="//www.mulle-kybernetik.com" target="_blank" class="link"><img class="inline-img" src="/objc-runtime-in-pictures/images/homepage-svgrepo-com.svg"></a> <a href="//www.mulle-kybernetik.com" target="_blank" class="link">WWW</a></div>
<div class="author-social"><a href="mailto:[email protected]" target="_blank"><img class="inline-img" src="/objc-runtime-in-pictures/images/email-svgrepo-com.svg"></a> <a href="mailto:[email protected]" target="_blank" class="link">Email</a></div>
<div class="author-social"><a href="//twitter.com/mulle_nat" target="_blank"><img class="inline-img" src="/objc-runtime-in-pictures/images/twitter-svgrepo-com.svg"></a> <a href="//twitter.com/mulle_nat" target="_blank" class="link">Twitter</a></div>
<div class="author-social"><a href="//github.com/mulle-nat" target="_blank"><img class="inline-img" src="/objc-runtime-in-pictures/images/github-svgrepo-com.svg"></a> <a href="//github.com/mulle-nat" target="_blank" class="link">Github</a></div>
<div class="author-social"><a href="//twitch.tv/Mulle_kybernetiK_TV" target="_blank"><img class="inline-img" src="/objc-runtime-in-pictures/images/twitch-svgrepo-com.svg"></a> <a href="//twitch.tv/Mulle_kybernetiK_TV" target="_blank" class="link">Twitch</a></div>
</div> <!-- bio -->
<div class="title">
<div>
<h2>Objective-C Runtime in Pictures <a href="/objc-runtime-in-pictures/feed.xml"><img class="inline-img" src="/objc-runtime-in-pictures/images/feed-icon-28x28.png"></a></h2>
</div>
<h6>© 2024 by Nat!, Mulle kybernetiK. All rights reserved.</h6>
<p>
</div> <!-- title -->
<div class="contents">
<h4>Contents</h4>
<ul>
<article>
<li class="no-bullet"><a class="internal-link" href="/objc-runtime-in-pictures/intro.html" title="Intro">Intro</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/objc-runtime-in-pictures/class.html" title="Class">Class</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/objc-runtime-in-pictures/ivar.html" title="Ivar">Ivar</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/objc-runtime-in-pictures/method.html" title="Method">Method</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/objc-runtime-in-pictures/property.html" title="Property">Property</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/objc-runtime-in-pictures/category.html" title="Category">Category</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/objc-runtime-in-pictures/protocol.html" title="Protocol">Protocol</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/objc-runtime-in-pictures/inheritance.html" title="Inheritance">Inheritance</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/objc-runtime-in-pictures/protocolclass.html" title="Protocolclass">Protocolclass</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/objc-runtime-in-pictures/quiz.html" title="Quiz">Quiz</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/objc-runtime-in-pictures/outro.html" title="Outro">Outro</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/objc-runtime-in-pictures/appendix.html" title="Appendix">Appendix</a>
</article>
</ul>
</div> <!-- contents -->
</div> <!-- sideline -->
</div>
<div id="post-second" class="eight columns">
<div class="title">
<div>
<h2>Objective-C Runtime in Pictures <a href="/objc-runtime-in-pictures/feed.xml"><img class="inline-img" src="/objc-runtime-in-pictures/images/feed-icon-28x28.png"></a></h2>
</div>
<h6>© 2024 by Nat!, Mulle kybernetiK. All rights reserved.</h6>
<p>
</div> <!-- title -->
<p>
<div id="main" role="main">
<article>
<h1>Appendix</h1>
<div>
<h2 id="syntax-topic">Syntax topic</h2>
<div class="language-objective-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">[</span><span class="n">obj</span> <span class="nf">methodWithArgument</span><span class="p">:</span><span class="n">argument</span> <span class="nf">additionalArgument</span><span class="p">:];</span>
<span class="p">[</span><span class="n">super</span> <span class="nf">method</span><span class="p">:</span><span class="n">argument</span><span class="p">];</span>
</code></pre></div></div>
<h2 id="method-call"><code class="language-plaintext highlighter-rouge">[method call]</code></h2>
<p>When you invoke or call an Objective-C method on an object, the object is
the <strong>receiver</strong> of a message. This is just nomenclature.</p>
<p>The receiver appears first in the method call, followed by the selector
interspersed with arguments in square brackets. So a call to method <code class="language-plaintext highlighter-rouge">- (void) insertObject:(id) obj atIndex:(NSUInteger) index</code> will look like this:</p>
<p><a href="images/method-call.svg"><img src="images/method-call.svg" alt="Method call deconstructed" /></a></p>
<h3 id="method-search">Method search</h3>
<p>So what does a method call do ? First it looks at the <a href="https://alwaysprocessing.blog/2023/01/19/objc-class-isa">isa</a>
pointer of the object. This will be a pointer to a <a href="class.html">class</a> object.
The class has
at least one methodlist. It can have multiple methodlists, if some were added
by <a href="category.html">categories</a>. The search order goes from back to front, so the most
recently added category methodlist comes first.</p>
<p>If no method has been found, the class may inherit methodlists from its
<a href="protocolclass.html">protocolclasses</a> and its <a href="inheritance.html">superclass</a>.
Again, the search order is back to first, the latest defined protocolclass is
searched first, then the others and the superclass last.</p>
<p>The superclass itself can be the same mixture of categories, protocolclasses
and a possible superclass.</p>
<p>Finally after the rootclass has been reached, and no method has been found yet,
the runtime will turn to forwarding (not part of this pamphlet) and if that
fails, the runtime will crash.</p>
<h3 id="super-method-search">Super method search</h3>
<p>The special super call, starts the message search from the “place” of
implementation. It will ignore all sibling methodlists of its implementation
class and then start a regular method search in the protocolclasses
and superclass.</p>
<h3 id="clobber-method-search">Clobber method search</h3>
<p>Only available with MulleObjC C runtime functions. This search stops at the
implementation class boundary. It searches backwards from the current
methodlist.</p>
<h3 id="override-method-search">Override method search</h3>
<p>Like the Clobber method search, but does not stop at the class boundary.</p>
<h2 id="case-studies">Case studies</h2>
<p><em>Only instance methodlists are shown for simplicity.</em></p>
<h3 id="class-a-the-simplest-case">Class A, the simplest case</h3>
<p><strong>A</strong> contains a method <code class="language-plaintext highlighter-rouge">instanceMethod</code>, its <code class="language-plaintext highlighter-rouge">@implementation</code> is not shown,
as it’s boring:</p>
<div class="language-objective-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">@interface</span> <span class="nc">A</span>
<span class="k">-</span> <span class="p">(</span><span class="kt">void</span><span class="p">)</span> <span class="n">instanceMethod</span><span class="p">;</span>
<span class="k">@end</span>
</code></pre></div></div>
<p><a href="images/A.svg"><img src="images/A.svg" alt="A" /></a></p>
<p>This is just for warming up. There is no <strong>super</strong> method in a root class,
and nothing has been overridden. So its <code class="language-plaintext highlighter-rouge">-instanceMethod</code> only.</p>
<h3 id="subclass-b-of-a-and-categories-on-b">Subclass B of A and categories on B</h3>
<p>B overrides the superclass method <code class="language-plaintext highlighter-rouge">instanceMethod</code>. And so do the two
categories P and Q on B. Again, implementations are not shown:</p>
<div class="language-objective-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">@interface</span> <span class="nc">B</span> <span class="p">:</span> <span class="nc">A</span>
<span class="k">-</span> <span class="p">(</span><span class="kt">void</span><span class="p">)</span> <span class="n">instanceMethod</span><span class="p">;</span>
<span class="k">@end</span>
<span class="k">@interface</span> <span class="nc">B</span><span class="p">(</span> <span class="nl">P</span><span class="p">)</span>
<span class="k">-</span> <span class="p">(</span><span class="kt">void</span><span class="p">)</span> <span class="n">instanceMethod</span><span class="p">;</span>
<span class="k">@end</span>
<span class="k">@interface</span> <span class="nc">B</span><span class="p">(</span> <span class="nl">Q</span><span class="p">)</span>
<span class="k">-</span> <span class="p">(</span><span class="kt">void</span><span class="p">)</span> <span class="n">instanceMethod</span><span class="p">;</span>
<span class="k">@end</span>
</code></pre></div></div>
<p>this will result in more complex layout:</p>
<p><a href="images/B.svg"><img src="images/B.svg" alt="B" /></a></p>
<p>As explained before, the search order will be from back to front.
So <em>methodlist #2</em> of B comes first, then <em>methodlist #1</em> of B, then
<em>methodlist #0</em> of B. The final search is through <em>methodlist #0</em> of A.</p>
<p>In short notation the various searches result in:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> super chain: B(Q) -> A
clobber chain: B(Q) -> B(P) -> B
override chain: B(Q) -> B(P) -> B -> A
</code></pre></div></div>
<h3 id="subclass-c-of-b-and-multiple-inheritance-with-protocolclasses">Subclass C of B and multiple inheritance with protocolclasses</h3>
<p>The next class <code class="language-plaintext highlighter-rouge">C</code> builds on <code class="language-plaintext highlighter-rouge">B</code> and has two protocolclasses added to the mix:</p>
<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">@protocol</span> <span class="nc">X</span>
<span class="k">@end</span>
<span class="k">@interface</span> <span class="nc">X</span> <span class="o"><</span><span class="n">X</span><span class="o">></span>
<span class="k">@end</span>
<span class="k">@protocol</span> <span class="nc">Y</span>
<span class="k">@end</span>
<span class="k">@interface</span> <span class="nc">Y</span> <span class="o"><</span><span class="n">Y</span><span class="o">></span>
<span class="k">@end</span>
<span class="k">@interface</span> <span class="nc">C</span> <span class="p">:</span> <span class="nc">B</span> <span class="o"><</span> <span class="n">X</span><span class="p">,</span> <span class="n">Y</span> <span class="o">></span>
<span class="k">@end</span>
</code></pre></div></div>
<p>The result looks like this:</p>
<p><a href="images/C.svg"><img src="images/C.svg" alt="C" /></a></p>
<p>Now with methodlist of <code class="language-plaintext highlighter-rouge">C</code> as the starting point, we get:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> super chain: C -> Y -> X -> B(Q) -> A
clobber chain: C
override chain: C -> Y -> X -> B(Q) -> B(P) -> B -> A
</code></pre></div></div>
<h3 id="class-d-inheritance-with-duplicate-protocolclasses">Class D, inheritance with duplicate protocolclasses</h3>
<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">@interface</span> <span class="nc">D</span> <span class="p">:</span> <span class="nc">C</span> <span class="o"><</span> <span class="n">Y</span><span class="p">,</span> <span class="n">X</span> <span class="o">></span>
<span class="k">@end</span>
<span class="k">@interface</span> <span class="nc">D</span><span class="p">(</span> <span class="nl">P</span><span class="p">)</span>
<span class="k">@end</span>
<span class="k">@interface</span> <span class="nc">D</span><span class="p">(</span> <span class="nl">Q</span><span class="p">)</span>
<span class="k">@end</span>
</code></pre></div></div>
<p><a href="images/D.svg"><img src="images/D.svg" alt="D" /></a></p>
<p>Before we go on, lets reconsider, that a protocolclass is a root class and
has no business calling “super” by itself. But if you were, here is what
would happen:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> super chain: D(Q) -> X -> Y -> C -> Y -> C -> ... -> INFINITE LOOP CRASH
clobber chain: D(Q) -> D(P) -> D
override chain: D(Q) -> D(P) -> D -> X -> Y -> C -> Y -> C -> ... -> INFINITE LOOP CRASH
</code></pre></div></div>
<hr />
<h2 id="api">API</h2>
<table>
<thead>
<tr>
<th>Method Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="language-plaintext highlighter-rouge">-performSelector:</code></td>
<td>Perform method taking no arguments</td>
</tr>
<tr>
<td><code class="language-plaintext highlighter-rouge">-performSelector:withObject:</code></td>
<td>Perform method taking one argument</td>
</tr>
<tr>
<td><code class="language-plaintext highlighter-rouge">-performSelector:withObject:withObject:</code></td>
<td>Perform method taking two arguments</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>Function/Method Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="language-plaintext highlighter-rouge">MulleObjCObjectPerformSelector0</code></td>
<td>Call method with no arguments</td>
</tr>
<tr>
<td><code class="language-plaintext highlighter-rouge">MulleObjCObjectPerformSelector</code></td>
<td>Call method with one argument</td>
</tr>
<tr>
<td><code class="language-plaintext highlighter-rouge">MulleObjCObjectPerformSelector2</code></td>
<td>Call method with two arguments</td>
</tr>
<tr>
<td><code class="language-plaintext highlighter-rouge">MulleObjCIMPCall0</code></td>
<td>Call implementation with no arguments</td>
</tr>
<tr>
<td><code class="language-plaintext highlighter-rouge">MulleObjCIMPCall</code></td>
<td>Call implementation with one argument</td>
</tr>
<tr>
<td><code class="language-plaintext highlighter-rouge">MulleObjCIMPCall2</code></td>
<td>Call implementation with two arguments</td>
</tr>
<tr>
<td><code class="language-plaintext highlighter-rouge">MulleObjCIMPCallWithFloat</code></td>
<td>Call implementation with float argument</td>
</tr>
<tr>
<td><code class="language-plaintext highlighter-rouge">MulleObjCIMPCallWithDouble</code></td>
<td>Call implementation with double argument</td>
</tr>
<tr>
<td><code class="language-plaintext highlighter-rouge">MulleObjCIMPCallWithLong</code></td>
<td>Call implementation with long argument</td>
</tr>
<tr>
<td><code class="language-plaintext highlighter-rouge">MulleObjCMakeObjectsPerformSelector0</code></td>
<td>Call method on array of objects with no args</td>
</tr>
<tr>
<td><code class="language-plaintext highlighter-rouge">MulleObjCMakeObjectsPerformSelector</code></td>
<td>Call method on array of objects with one arg</td>
</tr>
<tr>
<td><code class="language-plaintext highlighter-rouge">MulleObjCMakeObjectsPerformSelector2</code></td>
<td>Call method on array of objects with two args</td>
</tr>
<tr>
<td><code class="language-plaintext highlighter-rouge">MulleObjCObjectSearchSuperIMP</code></td>
<td>Find superclass implementation of a method</td>
</tr>
<tr>
<td><code class="language-plaintext highlighter-rouge">MulleObjCObjectSearchSpecificIMP</code></td>
<td>Find method implementation in specific class/category</td>
</tr>
<tr>
<td><code class="language-plaintext highlighter-rouge">MulleObjCObjectSearchOverriddenIMP</code></td>
<td>Find overridden implementation of a method</td>
</tr>
<tr>
<td><code class="language-plaintext highlighter-rouge">MulleObjCObjectSearchClobberedIMP</code></td>
<td>Find implementation clobbered by a category</td>
</tr>
</tbody>
</table>
</div>
</article>
</div>
<p>
<div class="left-right" id="pn-container">
<div class="left-half">
<span class="link">
Back to <a rel="prev" class="internal-link" href="/objc-runtime-in-pictures/outro.html">Outro</a>
</span>
</div>
<div class="right-half">
</div>
</div> <!-- left_right -->
</div> <!-- eight columns -->
</div> <!-- row -->
</div> <!-- container -->
</body>
</html>