"iOS Development" summary of classes in Objective-c

Source: Internet
Author: User

1 The creation of the class:

@interface Car:nsobject

{

Variable name

}

Method declaration

@end


@implementation Car

Implementation of the method

@end


2 class Inheritance (OC does not support multiple inheritance, you can achieve multi-inheritance effects through other features, such as "category" Catergory and "Protocol" protocol)

@interface Circle:car

@end

2.1 "Post-inheritance method scheduling problem:

When the code sends the message, the calling method will first go inside itself to find out if there is no such method, if not it will go to his parent to find, know NSObject class inside. If not, an error will occur.


2.2 The problem of instance variables after inheritance:

An ISA instance variable is declared in the NSObject class, and a pointer to the current class is saved. So each class will have the class that the instance variable points to itself, so the instance variable that the subclass owns is its own instance variable plus the instance variable in the parent class and the ISA instance variable in the NSObject class.


2.3 "Inherited rewrite method problem:

overriding methods sometimes to change an instance variable declared in a parent class, you need to invoke the method in the parent class using the Super keyword.


3 "Compound relationship (that is, multiple classes are used in a class)

1 The description method is like the ToString () method in Java, and NSLog (@ "%@") calls the description method by default.

So to print an object can rewrite his description method


4 "Construction method

The method of constructing the class in OC is the Init method, overriding the Init method

-(ID) init

{

if (Slef =[super init])

{

、、、、、、

}

return self;

}


5 "Setter and getter method

The setter method is preceded by a set, and the Get method does not need to add a get, only the variable name is required.


Inheritance is a is-a relationship, and the compound is a has-a relationship.


"iOS Development" summary of classes in Objective-c

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.