OC
Basic types of
- Scalar type
- int, long, char, float, double .(unsigned)
- integer(int/log), CGFloat(float/double)
- Boolean (YES/NO)
- The enumeration
- The numerical
- Derived types
- array, struct, function, union
Foundation
- NSNumber encapsulates a basic type into an object; NSNumber supports literals
- NSString, its literals are written like this
@"a string"
- NSData & NSDate
- NSData: binary representation of data (encapsulated in bytes). Encoding&Decoding
- NSDate: time processing and date representation; Simple timestamp retrieval
- NSArray
NSArray *array = @[@1, @2, @3]
- Array out of bounds handling and nil protection
- NSDictionary
- Provide a series of functions for KV operation
- Notice the nil protection
- NSString, NSArray, NSDictionary, use copy
- A deep or shallow copy of the collection
Define Class
- Inheritance relationships
- Property: the property
- Ivar Member variables
- getter && setter
- Modifiers: use of copy, strong, assign, weak
- Function (method)
- selector
- Class functions and member functions
The category and the Extension
- category
- Ivar cannot be added
- Add functionality to the class
- Separate class implementation
- Extension
- Increase ivar
- It is used to separate interfaces
- private
protocol
- Protocols Define Messaging Contracts
- Open closed principle, abstract class function, hidden concrete implementation class
- Protocols can inherit from other protocols
- Protocol constraints are weak and tend to produce only warnings without affecting the final compilation
Method Dispatch
- Definition and implementation
- Function overloading (NO) Function overwriting (YES)
- Subclasses have methods of the same name as their superclasses
- Dynamic resolution
- Force a static call to a superclass method
- selector vs. method
- Selector is char star
- The method address is the function address
- objc_msgSend
- OC messaging
- The dynamic analysis
- method lookup
- Inheritance chain
- Type encoding
- Method type coding
Memory management
- ARC: Automatic reference count
- Manual call retain/release/autorelease
- Memory management is difficult, prone to memory leaks and wild Pointers
- Reference counting and MRC
- Strong, weak, assign
- Ownership and object reference diagrams
- The best implementation
- Base type Assign
- Deltegate with weak
- NSarry, NSDictionary, NSString, block uses copy
- Other use strong
- The self in the block breaks the loop reference with weak
- Avoid referencing the ring A-strong -> B-strong -> C-strong-A
- Autoreleasepool
- A circular reference
Block
- Block Type
- inline block
- global block
- As a property && param
- Capture Var
- Copy value (copy pointer address, const)
- __block(heap var, mutable)
- Avoid circular references
- self->task->block->self
- self->task->block->weakSelf
RunTime
- The structure of classes and objects at run time
- The ability to access and modify class structures at runtime
- Opensource.apple.com/source/objc…
- Add a new class using Runtime