What type is a Swift closure

  • Value type – Each instance has a copy of its data. When assigned to a variable or constant, or passed to a function, it creates a new copy.

  • Reference type – All instances share a copy of the data. When assigned to a variable or constant, or passed to a function, a reference type, once initialized, returns a reference to an existing instance.

  • All except class and closure are value types

Why does the layer restore after coreAnimation

  • Because the animation generated is an illusion, it does not change layer in essence. Here we need to talk about the rendering tree in the layer tree. The rendering tree is actually a copy of the model tree, and its attribute values determine the current display effect. So after the animation ends it will revert to the original state.

Ask if the model tree is hidden or removed or overwritten while the rendering tree is working

  • Hope everybody takes guy to answer me
  • Modellayer (Model tree) should be a data Model, only put the data, the presentationlayer (tree) is the real presentation of the appearance, similar to MVC Model and View, one is responsible for the data, the other presentation, in the animation process, There is nothing hidden or removed (I printed it in timer during animation, Modellayer is always there and transparency and Ishidden are fine)

How does Array design allocate memory

  • __NSArrayM uses circular buffers. This data structure is fairly simple, just a bit more complicated than a regular array or buffer. The contents of a circular buffer can go around to either end as they reach the other.
  • Ring buffers have some really cool properties. In particular, insertion or deletion at either end does not require any memory to be moved unless the buffer is full. Let’s look at how this class makes full use of the ring buffer to make itself much more powerful than C arrays. At any one end inserted or deleted, just modify the offset parameters, memory, without moving when we visit as how much the index is not just a regular array, here will add offset the value of the data after processing, not inserted into the head and tail, ring structure will be based on the least mobile insert memory pointer way, For example, to insert between A and B, according to the array C, we need to move the elements from B to E, but in the design of the ring buffer, we only need to move the value of A forward one unit of memory, and change the offset at the same time, so as to ensure the smallest move unit to complete the intermediate insert.
  • If the data structure of the ring buffer is a continuous array structure, it will inevitably move a lot of memory during expansion, so it is better to implement the ring buffer with a linked list
  • CFArray, or immutable array, is implemented by a two-ended queue

Design your own arrays for a UITableView

  • Visible cell array
  • Cache pool array

Swift closure and OC block

  • A block already captures local variables when implemented, whereas a Swift closure captures local variables when invoked
  • The Swift closure adds a __block to automatic variables by default, and you can change the value directly
  • The Swift capture list can also achieve the same capture as the block
Var I = 1 let closure = {[I] in print("closure \(I)")} I += 1 print("out1 \(I)") print("out 2 \(I)") // Closure () print("out 2 \(I)" 2 1 2Copy the code
  • Block is not a return value or a return value of a function. Closure is available in Swift as another Closure or as the return value of a function.
  • When using optional types, make it clear whether the closure intercepts an optional type or an instance variable. This is the correct way to determine whether a circular reference has occurred.

The block life cycle

  • 1, the Block pointer is released after the method or function ends, and memory is stored in the Stack.

  • 2. If you want to save a Block pointer, you need to use the copy method (similar to NSObject), where the internal storage is stored in the Heap.

  • 3. Variables in the Block function body will be automatically retained and released after the Block ends.

  • 4. Variables identified with a __block prefix do not automatically Reatin.

  • 5. If you operate on self directly within a block, self will be retained automatically.

  • 6. If you manipulate a class variable in a block, the class to which the variable belongs is automatically retained

Avoid HTTPS man-in-the-middle attacks

  • MD5 check sign?
  • Transmitting insensitive data?
  • Does the client not install forged certificates?
  • Beg everybody to take guy answer to do not quite understand

Weak low-level implementation

  • Weak is that the Runtime maintains a hash table for storing all Pointers to an object that is weak. The weak table is a hash table where Key is the address of the pointer to the weak object and Value is an array of addresses of the pointer to the weak object.