Summary of basic principles of iOS

In clang-compiled CPP files you can see that the strong & copy & weak modified properties differ in the compiled underlying code

Strong, copy, and weak Underlying analysis

  • In LGPerson we define two properties, which are copy and strong respectively
  • withclangwillmain.mFile compiled intomain.cpp, and find copy andstrongOf the attribute modifiedsetThere is a difference in methods

Copy attributes use objc_setProperty, but strong attributes do not.

  • Search in LLVM"Objc_setPropertyFind the followinggetOptimizedSetPropertyFnIn the method

  • You can see from this that the returns are different for different modifiers

  • For atomic & copy decoration, name is objc_setProperty_atomic_copy

  • If it is atomic and there is no copy modifier, name is objc_setProperty_atomic

  • For nonatomic & copy, name is objc_setProperty_nonatomic_copy

  • The remaining combinations, namely nonatomic, nonatomic & Strong, nonatomic & weak, etc., have the name objc_setProperty_nonatomic

The above names correspond to the following methods in objC-818.2 source code

And then through assembly debugging, you find that you end up at objc_storeStrong

  • Assembler debugging results for properties modified by copy

  • Strong modifies the result of assembly debugging

  • Source searchobjc_storeStrong, there are the following source code, mainly alsoRetain new value, release old value

  • LLVM compiled source code searchobjc_storeStrongTo findEmitARCStoreStrongCallMethod, as shown in the figure below, finds that copy and strong modified properties enforce inconsistent policies

  • LLVM search EmitARCStoreStrongCall method in GenerateCopyHelperFunction method calls, then here found strong and weak of different processing

  • BlockCaptureEntityKind has the following enumerated values and their meanings

  • If it is weak, run the commandEmitARCCopyWeakMethod, as shown below, weak is called at the bottomobjc_initWeak

  • If the value is strong, run the commandEmitARCStoreStrongCallmethods

conclusion

  • The copy and strong modified attributes are inconsistent in the underlying compilation, mainly as a result of different processing of them in LLVM. Copy is assigned by objc_setProperty, while strong is assigned by self + memory translation (i.e., the pointer is shifted to name and then assigned) and then restored to strong

  • Strong & Copy calls objc_storeStrong underneath, essentially with the new value retain and the old value release

  • Weak Calls objc_initWeak at the bottom

Type Encoding & Property Type String

Type Encoding- Official document

Property Type String- Official documentation

Method signatures in CLang

Type encoding

What do these characters in the method list mean when compiled in Clang

@ @ 0:8 16, for example

  • @16 means the return string takes up 16 bytes — 8 bytes for the second @ and 8 bytes for sel

    • The first @ represents the return value

    • 16 indicates the total number of bytes 16 bytes

    • Second @ : the first argument

      • Id — @ Configuration type
      • typedef struct objc_object *id
    • 0 — 0 minus 8 starting at 0

    • : — represents SEL, method number

    • 8-8-16

  • In v24@0:8@16, v — void has no return value

See the list below for more information

Attribute of the clang compiled attribute

Clang compiles the attributes for the attributes, which can also be obtained using the property_getAttributes method

  • Tsaidtype
  • @saidVariable types
  • Csaidcopy
  • Nsaidnonatomic
  • VsaidvariableThe underline variable_nickName

See the list below for more information