Little fat says things------iOS extern,static and const differences and usage

Source: Internet
Author: User

In Layman's words:

when the extern field is used, the declared variable is a global variable and can be called, as well as a narrower term: extern can extend a variable in one class to another class;

Static variables declare variables, variable values after the change, save this change, each time you use to read the value;

Const declares that the value of a variable is immutable, is a property of ReadOnly, and cannot be changed.


Specific usage:

1.static usage: static nsstring *str = @ "haha";

2.const usage: nsstring *const str = @ "haha";

3.extern usage: In A.h, declare a variable extern nsstring *str = @ "123"; This declares a global variable, in the B.h inside the same write code extern nsstring *str, and then b.m inside directly print str can print out 123来, when used without the need to import A.h file header, or whether the classification has been created and so on.


Hope to have some help, later when writing code can be more tall on some, is also a skill.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Little fat says things------iOS extern,static and const differences and usage

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.