[Study Notes-Objective-C] Chapter 10 variables and Data Types in Objective-C Programming 6th, objectivec static variables

Source: Internet
Author: User

[Study Notes-Objective-C] Chapter 10 variables and Data Types in Objective-C Programming 6th, objectivec static variables
Part 1. instance variables and attributes

  • The current trend is to use (_) as the start character of the instance variable name.
  • In the implementation part, explicitly declare that the instance variable is private
    • ThereforeNoIn the subclass, you can directly obtain the instance variable value by name.
    • OnlyInherited access methodObtains the value of an instance variable.
  • Not Required@synthesizeCommand to generate an access method, as long as it is declared in the attribute.
Part 2. Global Variables
  • Lowercase g is the first letter of the global variable:int gMoveNumber = 1;Is also an external variable.
  • External variables: variables that are accessed and changed by any other method or function
  • Access: add keywordsextern:extern int gMoveNumber;
    • AddexternIs the declaration of the variable, not the definition. The Declaration will not cause variable storage space allocation, but will be defined.
    • If you use many methods to access global variables, perform the following operations at the beginning of the file:extern
    • If there are only a few accesses, it is best to separate them within each method.externStatement
Part 3. Static variables
  • Defined as a global variable, but not an external variable: Except for methods in a specific class, no other method needs to access this specific variable:static int gGlobalVar = 0;: Methods or functions after this statement can access the value of gGlobalVar, but not methods and functions in other files.
Part 4. enumeration data type
  • Enumeration type: provides a method to match an integer with a symbolic name.
    • To change the value of this integer, you can only change it in the place where the enumeration is defined.
    • Example:enum direction {up, down, left = 10, right};
    • The addition of element sequence, integer + 1, and so on.
Part 5. typedef statement

Typedef: change the data type name.

typedef int Counter;Counter j,n;
  • Added the readability of variable definitions and clearly showed the purpose of using these variables in the program.
Part 6. Data Type Conversion

Calculation of different data types:

  • If one of the operations islong double,double,floatType, the result is alsolong double,double,floatType.
  • If one of the operands is Bool, char, short int, bit field, or enumeration type, all are converted to int type.
  • If one of the operations islong long int,long intType, and the other operand is convertedlong long int,long intType, the result is alsolong long int,long intType.
  • Both operands areintType, the result is alsointType.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.