1, in OC, [] is used to adjust the method,. is also looking for methods, mainly to find the Get method,-> is used to find variables. _p is a direct access to instance variables.
2. In OC, the instance variable is a protection class and cannot be accessed externally, but when using @property and @synthesize, it is equivalent to having a set function and a Get function.
3, build setting Autorelease Reference counting automatic reference counter set to No, that is, open MRC.
4. Deep copy: Adds a pointer and re-opens up a space, this additional pointer points to the newly opened space, using this way of copying, to prevent the occurrence of repeated release of memory. Copy is a deep copy.
Shallow copy: Adds a pointer to an already existing memory space. Retain is a shallow copy.
5, @property parameter is readonly, does not generate the SET function, so can not be called with self, directly use the _+ variable name
6, Atomic: For each variable to lock operation, (jointly rob the same piece of resources, such as "Memory,"), the lock operation is able to make the resource used by a variable, will not appear because of each other waiting to appear "deadlock", waste resources (leveling use, allocation of use order, time-consuming) more than single-threaded, Occasionally, it can be used in multiple threads.
Nonatomic: To prevent the variable lock, save the system resources.
Locking: Is thread synchronization, to avoid multiple threads accessing the global variable at the same time caused the data to be destroyed, a thread after the lock, after the operation and then release the lock, if there are other threads want to access the locked variable will need to get the lock, and the lock is not released, only wait until the thread that owns the lock to release the lock, It means you can manipulate it.
7. Forward declaration: A forward declaration is used at the header file of the combined class, and the header file is imported in the. m file.
8. Thread Safety: The code runs in a multithreaded environment and runs in a single-threaded environment with the same results.
9. Combination class: Combination class in the. h file, use the parameter retain.
Strong: System-provided, custom pointer usage. Similar to the use of retain in MRC situations.
Weak: Weak reference. Whenever a pointer does not point to it, the memory is freed.
Copy: can also be used under ARC, equivalent to assign. However, with copy, you need to implement the Copywithzone method in the Nscopying protocol:
The MRC uses retain, copy, but copy can also be used under arc.
10, Autorelease lengthened the object's life cycle, let the object's release time to prolong, wasted memory, in the MRC use release as far as possible, but the specific use, is generally in multiple files call this object, not sure when release when the use of autorelease.
11. Using structs and enumerations in Object-c: (1) Accessing a member of a struct variable, using the. Member access operator. (2) struct pointer, struct member name. (3) (* struct pointer). struct MEMBER name
12. typedef struct oc_object{
Class Isa;
}* ID;
ID: The type of itself can be converted to any kind of object, as the return value is a deterministic type. D can be used to represent any object, which is a pointer to a objc_object struct type whose first member is a pointer to a objc_class struct type. Used when returning a value type, a row parameter type, and a parameter type.
ISA: the instance object of Isa points to its class. Isa of an object is pointing to the class of the object, and Isa for that object's class (class) points to Metaclass. Object-c the class object to the class structure pointed to by ISA in the instance object: The ISA in the class object points to the class structure called the static class member variable of the Metaclass,metaclass storage class and the static class member method (+) The ISA in the instance object is referred to as class structure (normal), the class structure stores the ordinary member variables of the classes and the ordinary member methods (-the method that begins).
The ISA for the instance object of the class points to its class, the class's Isa points to the class's Metaclass, the class's super_class to its parent class, and the value is NULL if the class is the root class. Metaclass Isa points to the root metaclass, if the metaclass is the root metaclass point to itself; Metaclass Super_class points to the parent metaclass, if the metaclass is the root meta Class points to the metaclass corresponding classes, and Object-c generates two objc_class for each class definition, one normal class, and the other is metaclass. We can create these two objc_class data structures at run time, and then use Objc_addclass to register class with the runtime system to dynamically create a new class.
13. Polymorphic: Use a pointer to a parent class to point to the object of the subclass, which is called to the correct version at run time.
(1) point to a subclass with a pointer to a base class
(2) The parent pointer is used as a formal parameter and can be passed as an argument using its subclass and itself
(3) In a composite class, it is better to refer to a high-level class as a member variable of a class
14, automatic release of the pool: (1) Be sure to call autorelease in the auto-release pool before the object is placed in the auto-release pool. (2) in the auto-release pool, the autorelease must be adjusted before the object is placed in the auto-release pool. (3) Whenever Autorelease is called in an auto-release pool, the object is placed in an auto-free pool.
15, classification and extension: Classification you can add methods to a class, but you cannot add variables. Extensions can either add methods or add variables. However, if an extension file is written separately, it is possible to access variables and methods. If you write an extension of a class to a. m file of a class, you can neither access the variable nor access the method.
16. String manipulation:
17, Nsarray created using nsarray *ary = [[Nsarray alloc] initwithobjects:@ "Jeo", @ "June", nil]; When used in multiple files, they are manually opened and not recycled. and Nsarray *arr = [Nsarray arryaywithobjects:@ "Jeo", @ "June", nil]; You can also use nsarray *ary = @[@ "Hello" @ "world"]; (This occurs after iOS8)
is System-managed, if used in multiple files, it will cause the program to hang out.
Whether an object exists in the array and returns a bool value: [Arr containsobject:@ "Jeo"];
To sort an array, use the system's method: Nsarray *ary = [arr sortedarrayusingselector: @selector (compare:)]; Because the ordering of the method does not affect the order of the original array, it needs to be received with a new array.
Fast traversal of arrays;
for (id num in ary) {NSLog (@ "%@", num);} There are different types of objects in the array, and it is best to use IDs to receive objects of any type.
18, the dictionary: there is no order of the points, because the dictionary is unordered
Nsdictionary *d= @{@ "1": @ "123" @ "2": @ "456"};
NSString *str = d[@ "1"];
Nsdictionary *d = [nsdictonary dictionarywithobjectsandkeys:@ "123", @ "1", @ "456", @ "2", nil];
NSString *str = [D objectforkey:@ "1"];
by Nsarray *ary = [D allvalues]; You can output all the values, and the same call [D AllKeys] can bring up all the keys.
Nsdictoinary *d = [nsdictonary dictionarywithallvalues:@ "123", @ "456" forkeys:@ "1", @ "2"]; You can also declare a dictionary
Nsmutabledictonary *dic = [Nsmutabledictonary dictionary];
[DiC setobject:@ "123" forkey:@ "1"];
[DiC setobject:@ "456" forkey:@ "2"]; add a key-value pair to the dictionary
[DiC removeobjetsforkeys:[nsarray arraywithobjects:@ "1"]; Delete a value
For (ID object in [dic allvalues]) {NSLog (@ "%@", object);}
Quickly traverse the dictionary and take out the values.
18, the file storage is the basic object, the class and object written by oneself is not written in, want to write into their own writing class, it is necessary to follow the Nscoding protocol, the overall file of the variable codec, implementation-(void) Encodewithcoder: (Nscode *) Acoder; to encode
-(Instancetype) Initwithcoder: (Nscode *) Adecoder; decode
But the code is an object, and a variable of the underlying type is converted to an object. The object of the class is then deposited into the file (archive): Person *p = [[Person alloc] init];
[Nskeyedarchiver archiverootobjectobject:p tofile:str];
Person *p = [Nsdeyedunarchiver unarchiveobjectwithfile:str];
Create file Management class: Nsfilemanager, General use Defaultmanager, commonly used classes:-(NSData *) Contentsatpath: (NSString *) path; The Currentdirectionarypath property manages the directory. Nshomedirectionary Gets the home directory, and [[Nsfilemanager Defaultmanager] currentdirectionary] Gets the current directory.
19, circular reference:
1. Circular referencing one of the variables using assign mode
2. No release for assign mode in Dealloc
OBJECTIVE-C Basic Knowledge Point Summary