iOS development and the like and objects

Source: Internet
Author: User

iOS development and the like and objects

OC and Java are a kind of object-oriented language, starting today I and everyone together to learn this object-oriented language OC, welcome you what problems with me to explore and learn.

The OC definition class has two steps: 1, the interface section (popularly speaking is. h file) 2, the implementation of the section (popularly speaking is. m file)

The interface section syntax is as follows:

#interface: Myclass:nsobject

{

int _count;

nsstring* _name;

-(ID) initwithstring: (nsstring*) Name;

+ (myclass*) creatmyclasswithstring: (nsstring*) Name;

}

@ end

Note: Class name: Myclass

Parent class: NSObject

Member variable declaration: int M_count;

nsstring* M_name;

Method declaration: -(ID) initwithstring: (nsstring*) Name;

+ (myclass*) creatmyclasswithstring: (nsstring*) Name;

The definition member variable is formatted as follows:

Type: Can be any of the basic data types allowed by the OC language, and can include basic types, constructed types, and various pointer types

Member variable: As long as it is a valid identifier, it is recommended that the OC member variable begin with (_) from Xcode4.

The method declaration is described as follows:

-(void) InsertObject: (ID) anobject atindex: (nsuinteger) index

Note: Method type identification:-

The method type identifies only + and-two + means that the method is a class method called directly with the class name-representing that the method is an instance method that must be used by an object to invoke

Implementation Section :

@implementation Myclass

{

int _count;

nsstring* _name; Member variables



}

-(ID) initwithstring: (nsstring*) Name

{

Define method body


}

+ (myclass*) creatmyclasswithstring: (nsstring*) Name

{

Define method body


}



iOS development and the like and objects

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.