UIView versus UIControl
-
UIView is focused on the page layout, because the addTarget: action: forControlEvents is defined in the UIControl, none of its superclass UIView, so there is no event interaction method, This can be done with the gesture UITapGestureRecognizer
-
UIControl focused on event interaction, the biggest characteristic is to have addTarget: action: forControlEvents method
-
UIControl inherits from UIView
What happens between Command plus B and Command plus R
- Simple iOS compilation
- A program that converts one programming language (the source language) into another programming language (the target language) is called a compiler.
- Most compilers consist of two parts: a front end and a back end
- The front end is responsible for lexical analysis, syntax analysis, generation of intermediate code
- The back end takes intermediate code as input, does line architecture-independent code optimization, and then generates different machine code for different architectures
- The front and back ends rely on a uniform format of intermediate code (IR) so that the front and back ends can change independently. Adding a language requires only a change in the front end, while adding a CPU architecture requires only a change in the back end.
- The build process
- Preprocessing (preprocessing takes the place of header import, macro replacement, comment processing, conditional compilation (#ifdef), etc.)
- Lexical analysis (converting input code into a set of language-specific lexical units, including keywords, operators, variables, etc., to tell the computer what it means)
- Parsing (The Token stream for lexical parsing is parsed into an abstract syntax tree, which Clang can parse to find errors in code. Such as a type mismatch, or an unimplemented message sent to target in Objective C)
- CodeGen (CodeGen traverses the syntax tree to generate LLVM IR code. LLVM IR is the output from the front end and the input from the back end. Objective C code Bridges the Runtime at this step.)
- Generate assembly code (LLVM optimizes LR to generate different object code for different architectures, and finally outputs it in assembly code format.
- Assembler (assembler takes assembly code as input, converts assembly code into machine code, and finally outputs object file main.c to main.o)
- The linker takes the compiled.o file and the (dylib,a, TBD) file to create a Mach-o executable.
- Operation process
- Dyld dynamic linker loads Mach-o files, recursively linking all dynamic and static libraries. A is also dyLD loaded into memory
- Rebase /binding (The loading address of executable files and dynamically-linked libraries in virtual memory is not fixed every time they are started, so these 2 steps are needed to fix the resource pointer in the image to the correct address. Rebase fixes Pointers to resources inside the current mirror; Bind points to a resource pointer outside the mirror.
- The runtime phase calls map_Image to parse the executable file to register objc classes, initializes class objects, calls the +load method for classes and classes, and calls C++ statically initializers and __attribute__ modifiers
- DidFinishLaunchingWithOptions in the AppDelegate class:
The concrete implementation of dictionary
- NSDictionary uses hash tables to map and store keys and values. The design of hash functions affects the search and access efficiency of data. The more evenly data is distributed in the Hash table, the higher the access efficiency is. In Objective-C, NSString is usually used as the key value, and the internal hash function uses NSString as the key value to ensure that the nodes of the data are evenly distributed in the hash table.
- Key hash function to get the hash value
- Hash mod or some algorithmic array extension threshold is worth indexing
- Stores values based on indexes
- Hash conflict is open addressing to re-hash the extension threshold +1 or -1 again to get an index or direct index +1
Difference between block and function pointer
-
The similarities
-
1. Both Pointers and blocks can implement callbacks, are declaratively similar, and can be viewed as a code snippet.
-
2. Both function pointer types and Block types can be used as types for variables and function parameters. (After a typedef defines an alias, the alias is a type.)
-
-
The difference between
-
1. Function Pointers can only point to pre-defined blocks of function code (which can be defined in other files and passed in dynamically as function arguments). The address of the function is determined when the link is compiled.
-
2.Block is essentially an Objective-C object, a subclass of NSObject, that can receive messages.
-
3. A function can access only global variables, whereas a Block Block can access not only global variables, but also the readability of current stack and heap memory variables (of course, local variables modified by the __block access indicator can also be modified within the Block Block).
-
4. From the perspective of memory, a function pointer is just a section of executable code pointing to the code area, while a block is actually an object dynamically created in stack memory during the running of the program, to which a copy message can be sent to copy the block object to the heap memory to extend its life cycle. An experiment can be done on point 2. After defining the block, hit a breakpoint. After running Cmd+R, you can see in the debug window that the block is indeed an object with an ISA pointer. In addition, GCC compiles larger executables with blocks, which is probably due to blocks being objects.
-