Basic concepts of OC

Source: Internet
Author: User

1. OC header file for #import <Foundation/Foundation.h> meaning for importing the underlying framework;
2. The output form is NSLog (@ "format Declaration");@autoreleasepool, automatic release of the pool;
3. Have the BOOL type variable (yes,no); define the class yourself; right-click on the project name file, click New File, select Sorce, click Cocoa Class and click Next to Generate. h and. Files.
4.OC: Object-oriented language, process-oriented function, function, object-oriented language important class; In class, import files with #import, file names cannot be the same,
to extend the usage of bool, the ID type does not have to be added *.
Runtime run time:Runtime is the state in which a program runs (or is executed), that is, when you open a program to make it run on a computer, that program is in the running moment. In some programming languages, some reusable programs or instances can be packaged or rebuilt into a "runtime". These instances can be connected or called by any program while they are running
5. Object-oriented terminology:
(1). Class: A class is a structure that represents the type of an object, representing the abstraction of a batch of things (including the interface part and the implementation part).
(2). Object is a particular thing, specifically only one, the object is a column of the class, the difference between the object and the class is that the object is a particular thing, the class refers to a group of things, the instance is another term for the object,
(3) methods and messages: The method is what the class can do, generally through the object to make method calls; The-interface interface section is used to define the public interface of the class; [email protected] implements the information defined in the interface section, in part for the implementation of the class ; Student *student
(4) method:-| + (return type) method Name: Parameter list + number method called with class name
the difference between a class method and an object method: (1) The object method begins with a-number, the class method begins with a + number, and (2) The object method must use the object invocation, the class method must use the class invocation, and (3) the property is directly accessible in the object method, and the property cannot be directly used in the class method ; (4) Class methods and object methods can call each other (4.1) object methods can call the class method directly, (4.2) class method indirectly Call object method, (4.3) class method can call directly other class method (4.4) object method can directly call object method (self call).
class Method Application Scenario: If the method is not used in the attribute, then the class method can be used as much as possible with the class method, the class method is more efficient than the object method of execution. Class methods are typically used to define tool methods: string lookups, file operations, database operations.

(5) Properties: Add getter and Setter methods for student class, use @ Property(properties) (Strong nonatomic) (nsstring*)/(Assgin nonatomic) (int), @synthesize automatically generatedgetter and Setter. @Private(can only be used within their own class), @ Public, @protected() *stu.name [email protected]"AFFG"; Set method; Nslong.
(6). Set,get accessor; The member variable is encapsulated, the access rights of the variable are increased, and the value of the variable is limited. Only get can read only, set can only write; encapsulation: hide the implementation steps;
Summary: Assign initial values to multiple member variables at once, use the traversal initialization function, assign an initial value to a single member variable, and have no conditional restrictions, use attributes, assign a value to a single member variable, and constrain the use of the get set accessor.
in the-number method, self represents a pointer to the current class, and supper represents a pointer to the parent class;
in the + Good method, self represents a pointer to a parent class or a subclass.
the notation of the attribute: @property (strong nonatomic) nstring *name;
@property (assign nonatomic) int age; Property Builder; To simplify the code; compiler attributes

Basic concepts of OC

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.