OBJECT-C Basic article (-)

Source: Internet
Author: User

What is an agreement
is a kind of grammar like a real labor agreement etc.
Canonical interfaces to implement communication between objects
Just declare methods to conform to the class of the Protocol to implement
Methods have to be implemented and do not have to implement two kinds of
Commonly used for proxy deep copy archive (nscoding) specification interfaces
Different classes want to do the same thing common protocols standardize their behavior to achieve the purpose of standardizing interfaces
OC does not have much inheritance so with protocol
For example, later in the company code packaging different classes commonly used protocol specification
Arc
A memory auto-management mechanism that occurs after 1.IOS5 * (also automatically detects data types)
Do not need to make reference counters through retain as before
+1, or manually add release to reduce the reference counter by one
or Autolease.

Cannot display call DELEAOC

Retain/copy
Using copy must comply with the Nscoping protocol
Retain the object reference counter +|
Assign direct assignment is not an object reference counter plus minus
Autorelease the address of the object to release from his nearest auto-release Chi Riyan.
The Dealloc object's reference counter is automatically called when it is reduced to 0 dealloc

、、、、、、、、、、、、、
Self.name =xx is a set method that can kvo monitoring (SET/KVC) internally to consider memory management
_name is just a simple variable assignment, consider the memory under ARC, because this is a strong reference pointer by default

Category
Upgrading a class, adding methods to the original Class 2 cannot add attributes
3 Inherit all of the methods and properties of the parent class (including the method that the parent class adds to the category can also inherit)
Strong weak
is the syntax of arc, weak weak reference pointer weak object can be directly assigned value, and once this object is destroyed, weak decorated pointer to nil
Strong is a strong reference pointer that will automatically add +1 to the reference counter

Weak/asign
1 has the meaning of direct assignment.
2weak is the syntax for the arc, which modifies the weak reference pointer. Asign can be used under both arc and MRC, and the arc can only modify some basic data types, and the MRC may also be a modifier for weak reference object addresses.

Mixed
In the project target settings
Arc-fno-objc-arc
-fobjc-arc
O-c Multiple Inheritance
Instead of using a protocol, the essence is that there is not much inheritance, but it is possible to obey multiple protocols and inherit multiple classes.
The implementation of multiple protocol methods, and hence the effect of multiple inheritance, but the analogy, but no yarn relationship.
O-c There are no private variables, and private methods, if not how to implement

The member variables are protect protected by default, and can also be decorated as private provate.
But there's no private method.
In the declaration section is not declared (or declared in the class's anonymous category) in the implementation of the class implementation, to achieve a private effect, but the essence is no private method, because it can be accessed with a selector, this is the dynamic mechanism of o-c, there is no real private

#include #[email protected]
#import不用添加条件编译 # include must be conditional compilation prevents header files from being included multiple times resulting in duplicate definitions
@class forward to the declaration, the purpose is to prevent, mutual inclusion, tell the compiler, I will declare later, now define here, please release.


Copy-only object reference () deep copy when archived

MVC Framework design pattern is dozens of, now the C layer is too heavy to reduce the editing efficiency, all have an editor called MVVM

Object-independent code multiplexing enhances robustness and reduces software costs
Observer pattern
Notice, KVO

OBJECT-C Basic 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.