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 pathporting.html
533 lines (392 loc) · 29.7 KB
/
porting.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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
<!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>Porting: General Tips – De Re mulle-objc</title>
<meta name="description" content="Tips
">
<meta name="keywords" content="">
<!-- Twitter Cards -->
<meta name="twitter:title" content="Porting: General Tips">
<meta name="twitter:description" content="Tips Use the Foundation as your base and not the MulleFoundation, as Foundation also include objc-compat. Use envelope headers Rewrite code that imports specific headers to use the envelope header. Example: Rewrite #import <Foundation/NSObject.h> #import <Foundation/NSString.h> to #import "import.h" // or <Foundation/Foundation.h> without the modern workflow The exception being <Foundation/NSDebug.h>...">
<meta name="twitter:site" content="@mulle_nat">
<meta name="twitter:creator" content="@mulle_nat">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://www.mulle-kybernetik.com/de-re-mulle-objc/images/features/porting.png">
<!-- Open Graph -->
<meta property="og:locale" content="en_US">
<meta property="og:type" content="article">
<meta property="og:title" content="Porting: General Tips">
<meta property="og:description" content="Tips Use the Foundation as your base and not the MulleFoundation, as Foundation also include objc-compat. Use envelope headers Rewrite code that imports specific headers to use the envelope header. Example: Rewrite #import <Foundation/NSObject.h> #import <Foundation/NSString.h> to #import "import.h" // or <Foundation/Foundation.h> without the modern workflow The exception being <Foundation/NSDebug.h>...">
<meta property="og:url" content="https://www.mulle-kybernetik.com/porting.html">
<meta property="og:site_name" content="De Re mulle-objc">
<meta property="og:image" content="https://www.mulle-kybernetik.com/de-re-mulle-objc/images/features/porting.png">
<meta property="og:logo" content="https://www.mulle-kybernetik.com/de-re-mulle-objc/images/logo.png">
<link href="/de-re-mulle-objc/atom.xml" type="application/atom+xml" rel="alternate" title="De Re mulle-objc Feed">
<link href="/de-re-mulle-objc/index.rdf" type="application/rss+xml" rel="alternate" title="De Re mulle-objc Feed">
<link rel="canonical" href="https://www.mulle-kybernetik.com/porting.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">
<link rel="stylesheet" href="css/poppins.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="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="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="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="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="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="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>De Re mulle-objc <div style="font-size:10px; display: inline-block;">0.50.0</div> <a href="feed.xml"><img class="inline-img" src='images/feed-icon-28x28.png'></a></h2>
</div>
<h6>© 2025 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="/de-re-mulle-objc/intro.html" title="De Re mulle-objc">De Re mulle-objc</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/modern.html" title="Project Setup">Project Setup</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/pnp-source.html" title="Generic Headers">Generic Headers</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/pnp-dependency.html" title="Dependencies">Dependencies</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/modern-complex.html" title="Projects with Multiple Targets">Projects with Multiple Targets</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/good.html" title="Good mulle-objc Code">Good mulle-objc Code</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/basics.html" title="A complete class">A complete class</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/objects.html" title="Objects and Properties">Objects and Properties</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/printing.html" title="Printing">Printing</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/pnp-class.html" title="Plug And Play Class">Plug And Play Class</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/pnp-category.html" title="Plug And Play Category">Plug And Play Category</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/overridden.html" title="Advanced: Calling overridden methods">Advanced: Calling overridden methods</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/forward.html" title="Advanced: -forward:">Advanced: -forward:</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/protocolclass.html" title="Advanced: Protocolclasses allow default implementations">Advanced: Protocolclasses allow default implementations</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/classcluster.html" title="Advanced: Classcluster Classes">Advanced: Classcluster Classes</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/singleton.html" title="Advanced: Singleton classes">Advanced: Singleton classes</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/tps.html" title="Advanced: Tagged Pointer Classes">Advanced: Tagged Pointer Classes</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/differences.html" title="Porting: Differences to Objective-C 2.0">Porting: Differences to Objective-C 2.0</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/legacy.html" title="Porting: Legacy Workflow">Porting: Legacy Workflow</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/bad.html" title="Porting: Bad mulle-objc Code">Porting: Bad mulle-objc Code</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/porting.html" title="Porting: General Tips">Porting: General Tips</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/subscripting.html" title="Porting: subscripting">Porting: subscripting</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/arc.html" title="Porting: ARC">Porting: ARC</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/block.html" title="Porting: ^blocks">Porting: ^blocks</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/dotsyntax.html" title="Porting: . syntax for properties">Porting: . syntax for properties</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/generics.html" title="Porting: generics">Porting: generics</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/modules.html" title="Porting: @import">Porting: @import</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/package.html" title="Porting: @package">Porting: @package</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/protocol.html" title="Porting: Protocols are a kind of @selector">Porting: Protocols are a kind of @selector</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/property.html" title="Porting @property">Porting @property</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/synthesize.html" title="Porting: @synthesize is useless now">Porting: @synthesize is useless now</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/synchronized.html" title="Porting: Synchronized is gone">Porting: Synchronized is gone</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/varargs.html" title="Porting: Variable Arguments in Methods">Porting: Variable Arguments in Methods</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/nszone.html" title="Porting: NSZone">Porting: NSZone</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/unichar.html" title="Porting: unichar">Porting: unichar</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/cpp.html" title="Porting: Objective-C++">Porting: Objective-C++</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/xcodeproj.html" title="Porting: Xcode projects">Porting: Xcode projects</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/tools.html" title="Tooling: mulle-objc Tools">Tooling: mulle-objc Tools</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/coverage.html" title="Tooling: Coverage information">Tooling: Coverage information</a>
</article>
<article>
<li class="no-bullet"><a class="internal-link" href="/de-re-mulle-objc/reduction.html" title="Tooling: Code reduction">Tooling: Code reduction</a>
</article>
</ul>
<h5> Or read it like a <a href="book.html"><b>book</b></a>.</h6>
</div> <!-- contents -->
</div> <!-- sideline -->
</div>
<div id="post-second" class="eight columns">
<div class="title">
<div>
<h2>De Re mulle-objc <div style="font-size:10px; display: inline-block;">0.50.0</div> <a href="feed.xml"><img class="inline-img" src='images/feed-icon-28x28.png'></a></h2>
</div>
<h6>© 2025 by Nat!, Mulle kybernetiK. All rights reserved.</h6>
<p>
</div> <!-- title -->
<p>
<div id="main" role="main">
<article>
<h1>Porting: General Tips</h1>
<div>
<h2 id="tips">Tips</h2>
<p>Use the Foundation as your base and not the MulleFoundation, as Foundation also
include <a href="//github.com/mulle-objc/objc-compat">objc-compat</a>.</p>
<h3 id="use-envelope-headers">Use envelope headers</h3>
<p>Rewrite code that imports specific headers to use the envelope header.</p>
<p>Example: Rewrite</p>
<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp">#import <Foundation/NSObject.h>
#import <Foundation/NSString.h>
</span></code></pre></div></div>
<p>to</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>#import "import.h" // or <Foundation/Foundation.h> without the modern workflow
</code></pre></div></div>
<p>The exception being <code class="language-plaintext highlighter-rouge"><Foundation/NSDebug.h></code> or any other header not exposed by
<code class="language-plaintext highlighter-rouge"><Foundation/Foundation.h></code>.</p>
<h3 id="find-and-correct-uses-of-class_getinstancesize">Find and correct uses of <code class="language-plaintext highlighter-rouge">class_getInstanceSize</code></h3>
<p>Two typical uses for <code class="language-plaintext highlighter-rouge">class_getInstanceSize</code> are</p>
<ol>
<li>retrieve the amount of memory required to create an instance</li>
<li>locate the “extra” bytes allocated by <code class="language-plaintext highlighter-rouge">NSAllocateObject</code> at the end of an instance</li>
</ol>
<h4 id="instance-creation">Instance creation</h4>
<p>The number of bytes returned by <code class="language-plaintext highlighter-rouge">class_getInstanceSize</code> is the amount of bytes
required to hold an instance (including mulle-objc runtime overhead).
But the actual object will be at an offset. Pass the allocated memory to
<code class="language-plaintext highlighter-rouge">objc_constructInstance</code> and use the return value as the instance pointer.</p>
<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">id</span> <span class="n">obj</span><span class="p">;</span>
<span class="kt">size_t</span> <span class="n">size</span><span class="p">;</span>
<span class="kt">void</span> <span class="o">*</span><span class="n">allocation</span><span class="p">;</span>
<span class="n">size</span> <span class="o">=</span> <span class="n">class_getInstanceSize</span><span class="p">(</span> <span class="n">cls</span><span class="p">);</span>
<span class="n">allocation</span> <span class="o">=</span> <span class="n">calloc</span><span class="p">(</span> <span class="mi">1</span><span class="p">,</span> <span class="n">size</span><span class="p">);</span>
<span class="n">obj</span> <span class="o">=</span> <span class="n">objc_constructInstance</span><span class="p">(</span> <span class="n">cls</span><span class="p">,</span> <span class="n">allocation</span><span class="p">);</span>
<span class="p">...</span>
<span class="cp">#ifdef __MULLE_OBJC__
</span><span class="n">allocation</span> <span class="o">=</span> <span class="n">object_getAlloc</span><span class="p">(</span> <span class="n">obj</span><span class="p">);</span>
<span class="cp">#else
</span><span class="n">allocation</span> <span class="o">=</span> <span class="n">obj</span><span class="p">;</span>
<span class="cp">#endif
</span><span class="n">free</span><span class="p">(</span> <span class="n">allocation</span><span class="p">);</span>
</code></pre></div></div>
<h4 id="access-extra-bytes">Access extra bytes</h4>
<p>Remember that your class may be subclassed. An offset from the last known instance variable
in your class implementation may not be correct.</p>
<p>The proper and portable way to get a pointer to the extra bytes is:</p>
<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kt">size_t</span> <span class="n">size</span><span class="p">;</span>
<span class="kt">void</span> <span class="o">*</span><span class="n">allocation</span><span class="p">;</span>
<span class="kt">void</span> <span class="o">*</span><span class="n">extra</span><span class="p">;</span>
<span class="n">size</span> <span class="o">=</span> <span class="n">class_getInstanceSize</span><span class="p">(</span> <span class="n">object_getClass</span><span class="p">(</span> <span class="n">self</span><span class="p">));</span>
<span class="cp">#ifdef __MULLE_OBJC__
</span><span class="n">allocation</span> <span class="o">=</span> <span class="n">object_getAlloc</span><span class="p">(</span> <span class="n">obj</span><span class="p">);</span>
<span class="cp">#else
</span><span class="n">allocation</span> <span class="o">=</span> <span class="n">obj</span><span class="p">;</span>
<span class="cp">#endif
</span><span class="n">extra</span> <span class="o">=</span> <span class="o">&</span><span class="p">((</span><span class="kt">char</span> <span class="o">*</span><span class="p">)</span> <span class="n">allocation</span><span class="p">)[</span> <span class="nf">size</span><span class="p">];</span>
</code></pre></div></div>
<p>If you use <a href="https://github.com/MulleFoundation/objc-compat">objc-compat</a>, you
can use <code class="language-plaintext highlighter-rouge">object_getExtraBytes</code>, which does exactly the above.</p>
<h3 id="register-composed-selectors-before-using-messaging">Register composed selectors before using messaging</h3>
<p>If you compose a selector from a C string, you must then use <code class="language-plaintext highlighter-rouge">sel_registerName</code>
to acquire a <code class="language-plaintext highlighter-rouge">SEL</code> from the string. Then use this <code class="language-plaintext highlighter-rouge">SEL</code> for messaging.
(You can also use <code class="language-plaintext highlighter-rouge">NSSelectorFromString</code>)</p>
<h3 id="find-and-correct-uses-of-objc_msgsend-and-objc_msgsend_stret">Find and correct uses of <code class="language-plaintext highlighter-rouge">objc_msgSend</code> and <code class="language-plaintext highlighter-rouge">objc_msgSend_stret</code></h3>
<p>Use the <a href="https://www.mulle-kybernetik.com/weblog/2015/mulle_objc_meta_call_convention.html">mulle-objc MetaABI</a>
convention to pass parameters and inspect return values.</p>
<h3 id="find-and-correct-uses-of-protocol">Find and correct uses of <code class="language-plaintext highlighter-rouge">Protocol</code></h3>
<p><code class="language-plaintext highlighter-rouge">Protocol *</code> does not exist. Replace it with <code class="language-plaintext highlighter-rouge">PROTOCOL</code>. You can not treat
<code class="language-plaintext highlighter-rouge">PROTOCOL</code> as an object and message it.</p>
<h3 id="find-initialize-and-load-methods-and-add-dependency-information">Find <code class="language-plaintext highlighter-rouge">+initialize</code> and <code class="language-plaintext highlighter-rouge">+load</code> methods and add dependency information</h3>
<p>The proper dependencies must be declared, the only known dependency to exist is the runtime during loading and initialization. Everything else must be declared.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>MULLE_OBJC_DEPENDS_ON_LIBRARY( Foundation);
</code></pre></div></div>
<h4 id="move-class-extension-code-to-the-interface">Move class extension code to the @interface</h4>
<p>TODO</p>
<h4 id="fix-mismatching-property-and-ivar-names-rename-ivars">Fix mismatching property and ivar names (rename ivars)</h4>
<p>TODO</p>
<h4 id="issues">Issues</h4>
<ul>
<li>the runtime only knows about protocols that are adopted by a class</li>
<li>PROTOCOL in mulle-objc is a hash value (like a selector) a different type</li>
<li>you can not message protocols</li>
</ul>
<h3 id="there-is-no-enveloping-nsautoreleasepool-around-load-in-mulle-objc">There is no enveloping NSAutoreleasePool around <code class="language-plaintext highlighter-rouge">+load</code> in mulle-objc</h3>
<p>If you create ephemeral instances in your <code class="language-plaintext highlighter-rouge">+load</code> method, you should wrap
the code yourself inside an <code class="language-plaintext highlighter-rouge">NSAutoreleasePool</code>.</p>
<h3 id="sizeof-unichar-is-different">sizeof( unichar) is different</h3>
<p>Apple Foundation uses UTF-16 as unichar, whereas the mulle-objc Foundation
uses UTF-32 as unichar. As long as your code is not assuming 16-bit for its
size, there should be no problem.</p>
<p>When accessing string contents as <code class="language-plaintext highlighter-rouge">unichar *</code> with say <code class="language-plaintext highlighter-rouge">-dataUsingEncoding:</code>
use the generic <code class="language-plaintext highlighter-rouge">NSUnicodeStringEncoding</code> instead of <code class="language-plaintext highlighter-rouge">NSUTF32StringEncoding/NSUTF16StringEncoding</code>.</p>
<div class="language-objc highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="n">data</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span> <span class="nf">dataUsingEncoding</span><span class="p">:</span><span class="n">NSUnicodeStringEncoding</span><span class="p">];</span>
<span class="n">here_some_unichars</span><span class="p">(</span> <span class="p">(</span><span class="n">unichar</span> <span class="o">*</span><span class="p">)</span> <span class="p">[</span><span class="n">data</span> <span class="nf">bytes</span><span class="p">],</span> <span class="p">[</span><span class="n">data</span> <span class="nf">length</span><span class="p">]</span> <span class="o">/</span> <span class="k">sizeof</span><span class="p">(</span> <span class="n">unichar</span><span class="p">));</span>
</code></pre></div></div>
<p>TODO: How about printf with %S ?</p>
<h3 id="inout-">inout …</h3>
<p>These <code class="language-plaintext highlighter-rouge">@encode</code> adornments should still work, but they are not encoded
and decoded:</p>
<ul>
<li>in</li>
<li>out</li>
<li>inout</li>
<li>bycopy</li>
<li>byref</li>
<li>oneway</li>
</ul>
<blockquote>
<p>See: <a href="https://stackoverflow.com/questions/5609564/objective-c-in-out-inout-byref-byval-and-so-on-what-are-they">Stack Overflow</a></p>
</blockquote>
</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="/de-re-mulle-objc/bad.html">Porting: Bad mulle-objc Code</a>
</span>
</div>
<div class="right-half">
<span class="link">
Next <a rel="next" class="internal-link" href="/de-re-mulle-objc/subscripting.html">Porting: subscripting</a>
</span>
</div>
</div> <!-- left_right -->
</div> <!-- eight columns -->
</div> <!-- row -->
</div> <!-- container -->
<script>
document.querySelectorAll('pre').forEach((block) => {
const button = document.createElement('button');
button.className = 'copy-button';
button.innerHTML = `<svg aria-hidden="true" data-prefix="far" data-icon="copy" class="svg-inline--fa fa-copy fa-fw fa-1x" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 440 500"><path fill="currentColor" d="M384 336H192c-9 0-16-7-16-16V64c0-9 7-16 16-16h140l68 68v204c0 9-7 16-16 16zm-192 48h192c35 0 64-29 64-64V116c0-13-5-25-14-34l-68-68c-9-9-21-14-34-14H192c-35 0-64 29-64 64v256c0 35 29 64 64 64zM64 128c-35 0-64 29-64 64v256c0 35 29 64 64 64h192c35 0 64-29 64-64v-32h-48v32c0 9-7 16-16 16H64c-9 0-16-7-16-16V192c0-9 7-16 16-16h32v-48H64z"/></svg>`;
block.appendChild(button);
button.addEventListener('click', () => {
const code = block.querySelector('code');
navigator.clipboard.writeText(code.textContent).then(() => {
// Change icon to checkmark
const originalHTML = button.innerHTML;
button.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" width="16" height="16"><path fill-rule="evenodd" d="M20 5a1 1 0 0 1 0 1l-9 13a1 1 0 0 1-1 0l-7-6a1 1 0 0 1 1-1l5 6 10-13a1 1 0 0 1 1 0z" clip-rule="evenodd"/></svg>';
// Reset after delay
setTimeout(() => {
// Restore original icon
button.innerHTML = originalHTML;
// fidget this for reasons...
button.style.color = '#6a6a7c';
}, 500);
});
});
});
</script>
<!-- Matomo -->
<script type="text/javascript">
var _paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["setCookieDomain", "*.www.mulle-kybernetik.com"]);
_paq.push(["setDomains", ["*.www.mulle-kybernetik.com"]]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//www.mulle-kybernetik.com/matomo/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '1']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<noscript><p><img src="//www.mulle-kybernetik.com/matomo/matomo.php?idsite=1&rec=1" style="border:0;" alt="" /></p></noscript>
<!-- End Matomo Code -->
</body>
</html>