IOS Study Notes-Implementation of variable attributes

Source: Internet
Author: User

 

IOS Study Notes-Implementation of variable attributes

 

1,CodeNote:

Person. h

Person. h

 # Import <Foundation/Foundation. h> @ 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 annotation] @ synthesize reference @ Property Association @ interface cannot be referenced, or cannot be associated, an error is thrown.  */  # 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 <Foundation/Foundation. h> # 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 attribute. 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 (For details, 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.