码迷,mamicode.com
首页 > 其他好文 > 详细

简化只执行一次的写法

时间:2014-04-29 13:43:21      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:ios   objective c      

<h4 id="toc_0">标准的写法</h4>

<div class="codehilite"><pre><span class="err">空</span>

</pre></div>


<h4 id="toc_1">简化后的宏</h4>

<div class="codehilite"><pre><span class="sr">/**************************************************************/</span>

<span class="sr">//</span> <span class="err">执行一次</span>

<span class="c1">#undef XY_ONCE_BEGIN</span>

<span class="c1">#define XY_ONCE_BEGIN( __name ) \</span>

<span class="n">static</span> <span class="n">dispatch_once_t</span> <span class="n">once_</span><span class="c1">##__name; \</span>

<span class="n">dispatch_once</span><span class="p">(</span> <span class="o">&amp;</span><span class="n">once_</span><span class="c1">##__name , ^{</span>


<span class="c1">#undef XY_ONCE_END</span>

<span class="c1">#define XY_ONCE_END });</span>

</pre></div>


<h4 id="toc_2">简化后的写法</h4>

<div class="codehilite"><pre><span class="o">-</span> <span class="p">(</span><span class="no">IBAction</span><span class="p">)</span><span class="ss">clickOnce</span><span class="p">:(</span><span class="nb">id</span><span class="p">)</span><span class="n">sender</span> <span class="p">{</span>

<span class="no">XY_ONCE_BEGIN</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>

<span class="no">SHOWMBProgressHUD</span><span class="p">(</span><span class="err">@</span><span class="s2">&quot;only show once&quot;</span><span class="p">,</span> <span class="kp">nil</span><span class="p">,</span> <span class="kp">nil</span><span class="p">,</span> <span class="no">NO</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>

<span class="no">XY_ONCE_END</span>

<span class="p">}</span>

</pre></div>

简化只执行一次的写法

标签:ios   objective c      

原文地址:http://blog.csdn.net/uxyheaven/article/details/24672123

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!