OC Foundation First Day---Class of methods, classes and objects

Source: Internet
Author: User

1. How to define behavior for a class.

What we just talked about is how to define a feature for a class.

How do I define behavior? The behavior of ratione materiae 1 functions also ratione materiae a function.

The act is called a method in OC. In fact, the function is the same as the representation of 1 functional modules.

2. Define a method without parameters for the class.

The method of the class is also divided into two parts.

A. Declaration of methods

1). Location: Written outside of the large brackets of the Declaration class.

2). The syntax of the declaration:

-(return value type) method name;

-(void) sayhi;

The name of this method is called Sayhi;

B. Implementation of the method.

1). Location: Written in the implementation of the class.

2). The implemented syntax:

-(return value type) method name

{

Method body;

}

C. Invocation of the method.

A method defined in a class belongs to a class. The class cannot be used directly.

Therefore, the method defined in the class cannot be called directly.

If you have to. You have to create an object of 1 classes.

Then this object has the member instance variables, methods in the class template.

It is possible to invoke the object's methods through the object.

Call Syntax:

[Object name Method name];

[P1 Sayhi];

3. Declaration and implementation of a method with 1 parameters.

A. Declaration of methods

1). Location:

2). Syntax:

-(return value type) method Name: (parameter type) parameter name;

-(void) Eat: (NSString *) foodname;

Need to remember a little bit:

The name of this method is called Eat:

B. Implementation of the method:

1). position.

2). Syntax

Copy the declaration to remove the semicolon plus the braces will be written in the implementation of it.

-(return value type) method Name: (parameter type) parameter name

{

}

C. Invocation of the method

1). To invoke by object name.

2). Call syntax

[Object Name Method name: argument];

4). Methods with multiple parameters

A. Statement:

1). position.

2). Syntax

-(return value type) method Name: (parameter type) parameter name:(parameter type) parameter name:(parameter type) parameter name;

-(int) getsum: (int) NUM1:(int) num2;

The name of this method is called Getsum::

B. Implementation:

1). position.

2). Syntax

Copy the declaration of the method, remove the semicolon plus the braces will be implemented in it.

-(return value type) method Name: (parameter type) parameter name:(parameter type) parameter name:(parameter type) parameter name

{

The implementation of the method.

}

C. Call

1). Must be called by object name.

2). Syntax of the call

[Object Name Method Name: argument: actual parameter: argument];

3. Specification of method names with parameters.

1). Principles of Compliance. When called, it seems to be a coherent word.

Let the caller know what the function of this parameter is.

2). Specification:

If the method takes only 1 parameters. Then the method name:

-(return value type) method name with: (parameter type) parameter name;

If there are multiple parameters:

-(return value type) method name withxx: (parameter type) parameter name andxx: (parameter type) parameter name;

  

1. The same 1 classes can create more than n objects.

There is no effect between objects and objects. A familiar value of 1 objects is a value that does not affect a property of another 1 objects at all.

There is no relationship between multiple objects of the same 1 class.

The only relationship is that they're all created from the same 1 class templates

They have the same member properties, methods.

The value of the property is not affected by each other.

2. In the implementation of the method. You can access the member variables of this class directly.

What is the member variable that accesses the 1 objects?

This method is called through the 1 objects. Then the member variable accessed in this method ratione materiae the object.

Who will call this method, the member variable in this method ratione materiae who's.

3. When we declare 1 objects. If no value is assigned to the field of the object.

At this point the field of the object has a default value.

If the type of the field is the base data type then the default value is 0.

If the type of the field is OC pointer type. Then the default value is nil.

If the type of the field is a C pointer type then the default value is NULL

How to declare and implement a class

How to create an object

How to access members of an object

Declaration and implementation of methods

How to invoke a method.

OC Foundation First Day---Class of methods, classes 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.