Oc1-object-oriented, class, and object

Source: Internet
Author: User

/*

* * class name capitalized: Variable name and method name lowercase, using hump naming method.

* * The difference between @class and #import is to solve the deadlock problem caused by circular references.

(1) Self refers to the class object itself, and super is the parent class object itself. (2) Self is used to invoke methods of this class of objects, and super calls the method of the parent class.

1.1) class, class name,. Characteristics and behavior. 2) object: Is an instance of a class, 3) class is static, there is a code area, the object is alloc out, stored in the heap area, the object name in the stack area, 4) Each instance variable of the class has different values in different objects (except static variable) 5) method is only when called, Memory is only consumed when the program is running.

2. Definition class: Two-part interface and implementation section

3. The interface section declares the characteristics and attributes of a class, @interface class name : The behavior of the parent class name nsobject{The property of the public class} class @end

(1) A colon is an inheritance relationship, and Nsoject is the parent class of all classes.

(2) method declaration:-Is an instance method, + is a class method. The method name is mainly (:), the method type, the return type, the method name, the argument type, the parameter name.

(4) method invocation: 1) [Class name/Object name method name];2] Object name. Method name; (dot syntax)

4. Implementation section: @implementation class name -(void) method name 1{} -(int ) method name 2{} @end

5. Implementation of the class:

6. Object creation: (1) The object is declared by a pointer, and after requesting memory, the object needs to be initialized to call the Init method so that the method can be used.

(2) each object of the same class has a different storage space for the instance variable, and the method of that class is shared by each object of the same category.

(3) Initialization of an object: by convention, we require that the initialization method begin with Init , successfully return a dynamic type Object (ID), and, if it fails, return (nil),

(4) Specifies the initialization method, subclass initialization must invoke the initialization method specified by the parent class, and initialize the parent class by sending a message to super. Instead, you will invoke an additional initialization method (by sending a message to self) that has more parameters than yourself, and provide an initialization value for parameters that you do not have.

(5) When no initialization method is specified, the Init method is added automatically,

Class name * Object Name =[class name alloc]; request memory space.

Object Name =[object name init];??

7. @property The use of a set in. h, when declaring a method of a class, @synthesize implemented in a. m file, used when implementing the method name

in @property () brackets, you can fill in the following properties, readwrite default, ReadOnly read-only, no set method, assign default reference count does not increase, retain reference count increases by 1 actomic atomicity; Nonatomi C Non-atomic nature;

Atomic is a thread-protection technique in OC that prevents data errors by being used by another thread when it is not completed.

8. Dot syntax: self.mynumber=10;//settings; self.mynumber;//access;

9. global variable declaration in the static class:

10. Class inheritance @interfae Subclass: The parent class subclass can inherit the class, and you can have these instance variables.

(1) Inherited method overloads: Create a new method with the same name instead of the parent class ClassA method. condition that defines a new method with the same name, the new method must have the same return value type, and the number of arguments is the same as the overloaded method.

11. Permission control: The default is Project, which only supports single inheritance. Common things put in the parent class, the individuality of something placed in the subclass. The instance variable can be accessed through the pointer operator, but it violates the object-oriented idea.

12. Polymorphism: The multiple states of a thing, a different kind of object can define a method that shares the same name, and this is the representation of polymorphism.

(1) dynamic type: OC determines the actual type of the object at run time. (2) dynamic binding; When the program executes, it can determine how the object is called.

(3) polymorphic condition: There is an inheritance relationship, there is a method override, a declaration variable of the parent class points to the subclass object.

13. When programming can predict the problem that may occur during the program running: @try, @catch, @finally

*/

/*

* * Object-c is a C-language super, all syntax, in object-c. Some C and OC programs are incompatible. Incompatibility on the name

the OC string needs to be prefixed with @. "@ can also be a placeholder,%@ is a placeholder for the object type.

The data types in OC are objects, but there are special. : Nsinteger, CGFloat, (Core graphfic), Nslong, etc.

1. Object-oriented, object-oriented, all things are objects, he is a simulation of the real world of the idea, the object is the real world of every thing.

all programming languages are designed to solve real-life problems. The solution is by describing the scene in the real world.

(1) face-to-face features.

2. Object-oriented 2 concepts: Classes and objects (individuals of the class).

3. Class class name characteristics (attributes, member variables) behavior (methods);

(1) Class name capitalization, the rest of the hump naming law.

4. Object: Object name object property value is different,

5. Use of classes and objects. (1) Format: Class Name Object name =[[class name Alloc]init];alloc request memory, Init to request memory initialization.

(2) all objects are placed in the heap area. (3) We operate the invocation, all using the object's contents.

6.NSString is a data type, called a string type. NSLog is output function, print program log, printf function is similar. Can print out engineering information, direct information, and object information.

8. Invocation of function, invocation method: [Object name Method name]; The header file is declared through the braces property and can be called directly by the name of the property.

9. This method, not in the header file declaration, is inherited from the parent class, (1) Call initialization when the class initializes the object. (2) When called, the method name is fixed,

Oc1-object-oriented, class, and object

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.