Objective-C Lesson 1

Source: Internet
Author: User

What is objective-C? Objective-C is (OC ).

OC is a superset of C and fully compatible with C language. In addition to the features of C language, it also adds some new features, starting with @, such as @ interface and @ implementation.

@ Interface is used to define a subclass and can also be an API.

@intaerface Car : NSObject{    ShapeColor XXXX;    ShapeRect XXXX;      }

 

@ Implementation is used to define the class name. After defining the class name, you can use methods to redefine the parameter or name of the subclass, which is also the part of method implementation.

@implementation Car- (void) setFillColor : (ShapeColor)c{     fillColor = c; }//setFillColor

 

Method:

It is equivalent to the Function Definition in C, but it is different from the function definition.

The method has the method type (in '-' format), return value (Return Value 'void'), parameter type (INT, etc ). (PS: After the parameter type, you need to use a semicolon to Represent ':'. You can define a tag between the first parameter type and the second parameter type, or you can choose not to define it, according to your personal preferences .)

- (void) setFillColor: (ShapeColor) fillColor;

 

 

SELF: indicates the current class object or instance.

Self indicates the class itself, so you can directly [self class name]

 

Super: indicates the parent class object or instance of the current class.

+ Is used to reference the parent class.

-Is the object representing the parent class

 

Inheritance:

In C language, there are actually some headers similar to custom header files that can be used later, but the difference is different. in C language, you can customize and modify header files, but it cannot be modified on OC. nsobject is the ancestor of the vast majority on OC. Unless it is a special framework that you need to redefine, it will always inherit the features of nsobject.

@ Intaerface car: nsobject // car is the custom subclass, and nsobject is the parent class.

Inheritance has many advantages. Among them, it can reduce a lot of repeated content, thus reducing the time and effort that Programmers spend on modifying code.

 

Class and object:

A class is the abstraction of an object, and an object is a specific instance of a class. Classes are abstract and do not occupy memory, while objects are specific and occupy storage space. A class is a blueprint for creating objects. It is a software template that defines methods and variables included in a specific type of objects.

 

To be continued ....

Objective-C Lesson 1

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.