IOS learning notes-Implementation of variable attributes

Source: Internet
Author: User

1. Code Description:

Person. h

Person. h

# Import

@ Interface Person: NSObject

{

Int age, sex; // variable definition

Int height, width;

}

@ Property int age, sex; // attribute Definition

@ Property char height;

//-(Void) setAge;

-(Int) setAge1 :( int);

-(Int) setWH :( int) w :( int) h;

/* Method definition

Format

-(Returned data type) method name: (Data Type of parameter 1) parameter 1 Name: (Data Type of parameter 2) parameter 2 Name

*/

@ End

Person. m

Person. m

# Import "Person. h"

@ Implementation Person

@ Synthesize age, sex; // accessors

// @ Synthesize height;

/*

My annotations]

@ Synthesize reference @ property Association @ interface

If no reference or association is found, an error is thrown.

*/

# Pragma mark ------ setAge ----

//-(Void) setAge;

//{

// Age = 20;

//}

# Pragma mark ------ setAge1 ------

-(Int) setAge1 :( int)

{

Age =;

Return age;

}

# Pragma mark ------ setWH ------

-(Int) setWH :( int) w :( int) h // method implementation

{

Length = 100;

Height = 175;

Return age * height;

}

@ End

Main. m

Main. m

# Import

# Import "Person. h"

Int main (int argc, const char * argv [])

{

@ Autoreleasepool {

Person * person = [Person alloc];

[Person init];

Person. age = 1; // attribute

NSLog (@ "person. ag = % I", person. age); // output attributes. Pay attention to type Matching. Otherwise, an error is thrown.

NSLog (@ "person = % @", person); // output object

[Person setWH: 6: 10]; // Method

[Person release]; // If the ARC mechanism is used, release cannot be used.

}

Return 0;

}

2. My annotations (see the following three figures ):

@ Synthesize reference @ property Association @ interface

If no reference or association is found, an error is thrown.

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.