Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

Objective-C

proper way to write an Objective-C initializer

1
2
3
4
5
6
- (id)init {
    if ((self = [super init])) {
        // initialization code
    }
    return self;
}
https://snipt.net/embed/52db1a34c41233bf780f975ee0722098/
https://snipt.net/raw/52db1a34c41233bf780f975ee0722098/
52db1a34c41233bf780f975ee0722098
objective-c
Objective-C
6
2016-11-25T12:07:24
True
False
False
/api/public/snipt/795/
correct-way-to-write-a-cocoa-initializer
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="p">-</span> <span class="p">(</span><span class="kt">id</span><span class="p">)</span><span class="nf">init</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="k">if</span> <span class="p">((</span><span class="nb">self</span> <span class="o">=</span> <span class="p">[</span><span class="nb">super</span> <span class="n">init</span><span class="p">]))</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="c1">// initialization code</span> </span><span id="L-4"><a name="L-4"></a> <span class="p">}</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">return</span> <span class="nb">self</span><span class="p">;</span> </span><span id="L-6"><a name="L-6"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
cocoa, init, initializer, obj-c, objective-c
Copyrighted, illegal, or inappropriate content? Email [email protected].