Declare and use global variables

Source: Internet
Author: User
Global variables have always been a good thing and can bring a lot of convenience in development. The following describes how to use global variables during software development in iPhone: 1. Create constants. h file (the file name can be retrieved as needed), used to store global variables; 2. In constants. write the required global variable name in H, for example: Object-CCodeNsstring * master_url; // pointer type int count; // non-pointer type Note: initialization cannot be performed when defining global variables; otherwise, an error is returned! 3. Introduce this file in the file that requires the use of global variables: Object-C code # import "constants. H "4. initialize or assign a value to a global variable: Object-C code extern nsstring * master_url; master_url = [[nsstring alloc] initwithformat: @" http://www.wuleilei.com "]; // pointer type; allocextern int count; Count = 0; // non-pointer type 5. Use global variables: use [uiappcation sharedapplication] Like normal variables. delegate. name = @ ""; * appdelegate = (* appdelegate *) [[uiapplication sharedapplication] Delegate]; appdelegat E. Name = @ "Wang Cheng ";

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.