The block syntax was added in the iOS4.0 SDK , where more than a dozen APIs were used to block syntax. The block object is also inherited and NSObject, and is a C-language-level syntax and runtime feature . Similar to the standard C function
A copy of an object can be created using the copy or nutablecopy method. The original object is not affected when the copy is modified.
Copy : Must be implemented first
Nscopying Protocol ,
Creating an immutable copy (Such as nsstring, nsarray,
// Nsvalue can convert the C type to an objective-C object, such as nsange, cgpoint, cgsize, cgrect, cgvector, uiedgeinsets, and uioffset nsange range = nsmakerange (0, 1 ); nsvalue * rangevalue = [nsvalue valuewithrange: range]; // nsvalue converts
Introduction:
In the previous article, we talked about KVC. In this article, we learned KVO. The full name is: key value observing. the literal translation is: key value-based observer.
So what is its use? KVO is mainly used for view interaction.
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
Block is used to save a piece of code.
Block ID: ^Blick is similar to a function. 1. It can save code segments. 2. It has returned values. 3. It has parameters. 4. It has the same calling method.
Block definition:
Return Value Type (^ block name)
Automatically generated code, not garbage collection
Arc judgment criteria:
As long as there is no strong pointer to the object, the object will be released
1. Features of Arc
-Release, retain, and retaincount cannot be called.
-"Dealloc can be
Basic Principles:
1. What is memory management?-The memory of mobile devices is extremely limited, and each app can occupy a limited amount of memory.-When the app occupies a large amount of memory, the system will issue a memory warning, in this
Objective-C has a lot of dynamic features. Basically, it is also often mentioned and used with dynamic types (dynamic typing) and dynamic binding (dynamic binding) and dynamic loading (dynamic loading ).
These dynamic features are commonly used in
In objective-C, the method used to call a function is "message transmission". The difference between this method and a common function call is that you can transmit any message to an object at any time, instead of declaring these methods during
Four access controllers of member variables in objective-C:
@ PRIVATE: only the current class can be accessed internally.
@ Public: All users can access
@ Protected: only the current class and its subclass can be accessed.
@ Package: allow member
File description:
. H class declaration file, the user declares variables, functions (methods)
. M class implementation file, the user implements the function (method) in. h)
Class declaration using keywords @ interface, @ end
Class implementation
# Import @ interface classvirable: nsobject {nsinteger year; // protect the tree} @ property int age; // setage is available without @ synthesize in the implementation file: and age method-(void) set :( nsinteger) I; @ end
#import
OC (objective-C for short)
Based on the C language, an object-oriented syntax with the smallest scope is added (the most essential part of object-oriented is retained, and the content of OC is not much java, java does not have much content than C ++,
Struct
Nsange:
Used to indicate the range
Create
Nsange R1 = {2, 4}
Nsange r2 = {. Location = 2,. Length = 4}
Nsange R3 = nsmakerange (2, 4)
Search for the range of a string in Str
Nsstring * STR = @ "I love OC ";
Nsange range = [STR
Reference Counter
When an object is created, it must be allocated to the memory object. When this object is not used, it must be recycled in a timely manner. In order to clearly know whether the object has been used, it must be reflected by the
The code block is essentially similar to other variables. The difference is that the data stored in the code block is a function body. Using code blocks, you can pass in the number of parameters and get the return value just like calling other
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.