iOS variables are defined in. h or. m

Source: Internet
Author: User
<span id="Label3">Objective<pre><code>以前我定义变量一直都是定义在.h文件中,后来看别人的代码,发现很多人都把一些变量定义在.m文件中。后来我自己试了一把,发现变量既可以定义在.h文件中也可以定义在.m文件中,虽然这是个很小的问题,或许有些人会说既然都可以,那不随你定义在哪里喔,但是我一直觉得肯定会有区别的,后来我终于找到了一个能说服我的解释了。</code></pre>The variables are defined in The. h file<pre><code>@interface BaseTableViewController : BaseNavViewController{ UIView *backgroud; UIActivityIndicatorView *activity; UIImageView *imageNonet; UILabel *labError; UILabel *labRetry; }</code></pre>II. variables defined in. m files<pre><code>@interface BaseTableViewController (){ UIView *backgroud; UIActivityIndicatorView *activity; UIImageView *imageNonet; UILabel *labError; UILabel *labRetry;}</code></pre><p>In fact, these two definitions are not problematic in terms of wording, but they are problematic from the code Specification.<br>The. h file generally puts some externally exposed variables or methods, whereas. m files generally put some of their own private variables and METHODS. For example, we want to write an SDK for others to call, we put the written code into a static library, the caller can only see The. h file, then I will need to pass in the input variables and call methods written in The. H File. For some variables or methods that are not relevant to the caller and we need it ourselves, we can put them in The. m file. In fact, the popular saying is that the external public variables or methods are defined in The. h file, the internal-private variables or methods are defined in The. m file.</p><p>iOS variables are defined in. h or. m</p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.