Objective-c (class II and Object)

Source: Internet
Author: User

Classes and objects

#import is an upgraded version of include, which can automatically prevent repeated inclusion, so note: everyone will use import when introducing header files in the future

      Foundation is a framework, Foundation.h is the main header file of the Foundation framework

#import <Foundation / Foundation.h>

Find the path of the Foundation framework header file:

Applications / Xcode.app / Contents / Developer / Platforms / MacOSX.platform / Developer / SDKs / MacOSX10.9.sdk / System / Library / Frameworks

 The entrance to the oc program is the same as the c program, which is the main function

     the difference

     1. Different names

     2. Different header files introduced

     3. The format of printing is different. When printing, the parentheses after NSlog must start with @

     4. Different print content

     5.NSlog can wrap automatically

     6.printf prints the string of c, NSlog prints the string of oc

 

Classes in OC

There are three aspects of class relationships:

 1. Name (class name): the first letter is capitalized, if the name is composed of multiple words, the following words follow the camel case principle

 2. Attributes: Generally begin with an underscore.

 3. Behavior (method): lowercase first letter, followed by the camel case principle: write the behavior in the most direct object from the execution of this behavior

OC object

When you try to do something (execute function), you just write [class name / object method name] [method caller method name]

 1. The method called by the class name is called a class method

 2. The method called by the object is called the object method

Create an object

Example: Iphone * iphone1 = [Iphone new]; // [Class name / Object method name]

[Iphone new];

     1. Allocate memory space

     2. Initialize member variables (also called instance variables, which are attribute values in braces in the class declaration), and initialize integer values to zero

     3. The address of the return space

All classes in oc can be regarded as a data type

The oc object assigns values to member variables the same as the structure

A class can create many objects without affecting each other.

isa pointer is not created by us, it is a class member, hidden member variable

Object method

Object methods must begin with-. 2. All data types are enclosed in parentheses, and only data types are enclosed in parentheses. 3. The method name follows the camel case principle. 4. If there is no parameter, nothing is written after the method name. 5. The declaration of the behavior is written in the @interface class name: NSObject {} Below the braces, @end above

What methods are declared in the declaration, what methods are implemented in the implementation are implemented in @implematation class name @end above

Objective-C (type two and objects)

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.