snipt

Ctrl+h for KB shortcuts

Objective-C

Dynamically instanting classes in Objective-C

id obj = [[NSClassFromString(@"MySpecialClass") alloc] init];
https://snipt.net/embed/017e19107befb46e3e45ce38a56c6df0/
/raw/017e19107befb46e3e45ce38a56c6df0/
017e19107befb46e3e45ce38a56c6df0
objective-c
Objective-C
1
2019-07-15T09:21:30
True
False
False
/api/public/snipt/21186/
dynamically-instanting-classes-in-objective-c
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="kt">id</span> <span class="n">obj</span> <span class="o">=</span> <span class="p">[[</span><span class="n">NSClassFromString</span><span class="p">(</span><span class="s">@&quot;MySpecialClass&quot;</span><span class="p">)</span> <span class="n">alloc</span><span class="p">]</span> <span class="n">init</span><span class="p">];</span> </span></pre></div> </td></tr></table>
obj-c, objc