iOS Development Summary (A0)-#define and const

Source: Internet
Author: User

When to use # define, when to use const?

Effective Objective C ITEM4 says this:

Prefer Typed Constants to preprocessor #define

1. Avoid # define. Because there is no type information, and may be redefined

2. defined as a static const in M files (in fact this process is the same as # define)

3. For global constants, it should be stated in the header file, defined in the relevant m file, that the class name prefixed with the response

As in. h,

extern const Nstimerinterval Classanimationduration;

In. M,

Const Nstimerinterval? classanimationduration=0.3;

(As with various Notificaiton in uiapplication)

?

=====================

Note the const position, which modifies the const key before the keyword, such as

Static NSString * Const CONSTANT; Refers to the const pointer to an NSString

=====================

iOS Development Summary (A0)-#define and const

Related Article

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.