The article continues to update the like to see, form a habit, more please pay attention to! Read the next chapter on iOS

Basic path diagram:

There are a few important things to be clear about as we look at the basics of RunTime:

  • SEL
  • id
  • Class
  • Method
  • Ivar
  • IMP
  • Cache
  • Property

We can get all the information about a given class from these things, whether public or private, all of it, and manipulate it.

PS: But when working with private methods, be careful not to use them on shelves unless you have a way to get them approved by Apple.

The RunTime advanced

Advanced path diagram:

! [] (pic4.zhimg.com/80/v2-b1188…).

As we learn more about RunTime, we need to learn more about it.

Message mechanism:

  • objc_msgSend
  • objc_msgSend_fpret
  • objc_msgSend_stret
  • objc_msgSendSuper
  • objc_msgSendSuper_stret

Object association:

  • objc_setAssociatedObject()
  • objc_getAssociatedObject()
  • objc_removeAssociatedObjects()

Object association policy:

  • OBJC_ASSOCIATION_ASSIGN
  • OBJC_ASSOCIATION_RETAIN_NONATOMIC
  • OBJC_ASSOCIATION_COPY_NONATOMIC
  • OBJC_ASSOCIATION_RETAIN
  • OBJC_ASSOCIATION_COPY

Dynamic method parsing:

  • resolveInstanceMethod:

  • YES, is processed through the class_addMethod message, end

  • NO, enter forwardingTargetForSelector

  • You specify the response selector, the message gets processed, end

  • You don’t specify a response selector

  • Enter methodSignatureForSelector, specify the method signature, call forwardInvovation, through anInvocation do processing, message processing, over

  • No method signature was specified, the message was not processed, and the system reported an error

The RunTime application

Application path diagram:

! [] (pic4.zhimg.com/80/v2-33011…).

After learning about RunTime, we can apply it to our actual development.

Category

  • associations
  • Control object

Class

  • Dynamic addition method
  • Dynamic switching method
  • Intercept and replace methods dynamically
  • Add extra functionality to a method dynamically

Model

  • Automatic filing and filing

  • Automatic dictionary to model

  • Dictionary to model (model attributes more than dictionary keys)

  • Dictionary to model (nested model within model)

  • Dictionary to model (nested model in array)

RunTime instance development scenario

In real development, we have some example scenarios that use RunTime:

  • replaceViewControllerDeclaration cycle of
  • Solve the problem of collection class index crash
  • Prevent the button from repeated high-intensity clicking
  • Global replacement control initial effect
  • App hot repair
  • Abnormal App loading booth map
  • Global changesUINavigationBarbackButtonItem

Runtime Method Swizzling Development instance summary

RunTime interview questions and answers

Ble data-draft-node=”block” data-draft-type=”table” data-size=”normal” data-row-style=”normal”> What happens when OBJC sends a message to an object? r>ody>**b**le dat**a**-draft-node=”block” d**a**ta-**d**raf**t**-type=”table”** data-size=”normal” Data-row-style =”normal”>ody> question: When is an unrecognized selector error reported? What mechanisms does iOS have to avoid this? **able>ble data-draft-node=”block” data-draft-type=”table” data-size=”normal” data-row-style=”normal”>body>r> Can I add instance variables to the compiled class? Can I add instance variables to classes created at run time? Why is that? Tbody >ble data-draft-node=”block**” data-draft-type=”table” data-size=”normal” data-row-style=”normal”>body> How does runtime implement automatic nil for weak variables? R >>**b**le data-draft-node=”block**” data-draft-type=”table” data-size=”normal” data-row-style=”normal”> What elements in the class structure change when an attribute is added to the class ********

conclusion

Well, finally to the end, I hope you can learn knowledge in my article, marry Bai Fumei as soon as possible, onto the peak of life

Thanks for your support! The article continues to update the like to see, form a habit, more please pay attention to!

Read more about iOS. Read the next chapter.