1217.2--defines a class + method declaration call

Source: Internet
Author: User

To create a new class

New file->cocoa Class (parent class NSObject)

. h files are used to define properties and methods

. m files are used to specifically implement

Method declaration:

1 #import <foundation/foundation.h>2  @interface person:nsobject{3     nsstring *name;4     int age;5     NSString *address; 6} 7-(void) usetools;  method declaration without parameter return value 8-(void) SetName: (NSString *) AName Age   : (int) aAge;  Declaration of a parameter without a return value 9 @end

1. Age is a label that describes the function of the following functions

2.-Symbol, for instance method, must instantiate an object, call with Object

The + symbol, as a class method, does not need to instantiate an object that can be called directly from the class itself

3. The member variable is written in {}, and the method is written outside {}, before end

4. All declared methods must be implemented

Invocation of the method

1 #import <Foundation/Foundation.h> 2 #import "Person.h" 3  4 int main (int argc, const char * argv[]) {5     @au Toreleasepool {6 person         *hr = [[Person alloc]init]; 7         [hr setname:@ "HR" age:22]; 8         [HR Usetools]; 9     }10
   return 0;11}

1. #import "Person.h" into the header file

2. Person *HR = [[Person alloc]init]; allocate memory and initialize space

3. [] means message, who does what

4. [HR setname:@ "Huo" age:22]; label advantages

1217.2--defines a class + method declaration call

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.