iOS Development: Learning notes-variables, attributes, methods, implementations

Source: Internet
Author: User

1, Code Description:

Person.h

Person.h

#import

@interface Person:nsobject

{

Definition of int age,sex;//variable

int height,width;

}

Definition of the @property int age,sex;//property

@property char height;

-(void) setage;

-(int) SetAge1:(int) A;

-(int) Setwh:(int) w:(int) h;

/* Definition of method

Format

-(returned data type) method name:(parameter 1 data type) Parameter 1 is called:(Parameter 2 data type) parameter 2 is called

*/

@end

Person.m

Person.m

#import "Person.h"

@implementation person

@synthesize age,sex;//Accessor

@synthesize height;

/*

"My notes."

@synthesize Reference @property Association @interface

References that are not, or are not associated with, are thrown incorrectly.

*/

#pragma mark------setage----

-(void) setage;

//{

age=20;

//}

#pragma mark------setAge1------

-(int) SetAge1:(int) A

{

Age=a;

return age;

}

#pragma mark------SETWH------

-(int) Setwh:(int) w:(int) H//method implementation

{

width = 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;//Property

NSLog (@ "Person.ag =%i", person.age)//Output property, note type match, or throw wrong

NSLog (@ ' person =%@ ', person);/Output Object

[Person Setwh:6:10];//method

[Person release];//if the arc mechanism is used, release is not available.

}

return 0;

}

2, my comments (see below three pictures):

@synthesize Reference @property Association @interface

References that are not, or are not associated with, are thrown incorrectly.

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.