Objective-C Runtime Swizzle

318643095c83b914cf80a7f99f247fe6?s=47 Wei Wang
November 20, 2014

Objective-C Runtime Swizzle

318643095c83b914cf80a7f99f247fe6?s=128

Wei Wang

November 20, 2014
Tweet

Transcript

  1. 0CKFDUJWF$3VOUJNF 4XJ[[MF࣮ફ Ԧቨ 

  2. ࣗݾ঺հ w ઌ݄ೖࣾ͹͔Γɺ೥લ೔ຊ΁དྷͨ w J04։ൃ೥͙Β͍ɻલ৬6OJUZ% w ࠓ-JOF"ET4%,ͷ࢓ࣄΛ୲౰͍ͯ͠Δ w ࠷ۙ"OESPJE΋ษڧத w

    IUUQHJUIVCDPNPOFWDBU
  3. Ͳ͏ͯ͠0CKFDUJWF$͕ੜ͖Δ ͔Βɺࠓ·Ͱࡀ΋ա͗ɻݴޠʹͷ͓೥دΓ

  4. None
  5. 4NBMM5BML ϝοηʔδૹ৴ 4XJ[[MJOH ϝλݴޠ $ͱ$ ޓ׵ "3$ "TTPDJBUFE 0CKFDU --7.$MBOH

    ($% ັྗతͳ ॊೈੑ
  6. 4XJ[[MJOH

  7. .FUIPE$BMMJOH ClassName *object = [[ClassName alloc] init]; [object doItWithA:a]; objc_msgSend(object,

    @selector(doItWithA:), a); %JTQBUDI5BCMF .FUIPE *.1 @selector(doIt) doIt @selector(doItWithA:) doItWithA: - (void)doIt { //... } - (void)doItWithA:(id)a { //... }
  8. .FUIPE4XJ[[MJOH %JTQBUDI5BCMF .FUIPE *.1 @selector(doIt) doIt @selector(doItWithA:) doItWithA: @selector(alt_doItWithA:) alt_doItWithA:

    - (void)doIt { //... } - (void)doItWithA:(id)a { //... } - (void)alt_doItWithA:(id)a { //... } EP*U8JUI"ͱBMU@EP*U8JUI"Λ4XJ[[MF͠·͢
  9. .FUIPE4XJ[[MJOH %JTQBUDI5BCMF .FUIPE *.1 @selector(doIt) doIt @selector(doItWithA:) doItWithA: @selector(alt_doItWithA:) alt_doItWithA:

    - (void)doIt { //... } - (void)doItWithA:(id)a { //... } - (void)alt_doItWithA:(id)a { //... } EP*U8JUI"ͱBMU@EP*U8JUI"Λ4XJ[[MF͠·͢
  10. .FUIPE4XJ[[MJOH %JTQBUDI5BCMF .FUIPE *.1 @selector(doIt) doIt @selector(doItWithA:) doItWithA: @selector(alt_doItWithA:) alt_doItWithA:

    - (void)doIt { //... } - (void)doItWithA:(id)a { //... } - (void)alt_doItWithA:(id)a { //... } *.1Λަ׵͠·͢
  11. %FNP -JOF"ET4%,ΦϦΤϯςʔγϣϯ

  12. αϚϦʔ w ΫϥεͷϝιουςʔϒϧΛॻ͖׵͑Δ w ڧྗͰ͋ΔͨΊཚ༻Λආ͚Δ΂͖ w ඞͣަ׵લͷϝιʔυΛݺͼ·͢ w ΫϥεͷΧςΰϦʔͱ MPBE࿈ܞ͕Φεεϝ

  13. '"2 NBJMXFJXBOH!MJOFDPSQDPN )JQ$IBUPOFWDBU %FNPDPEFIUUQTHJUIVCDPNPOFWDBU-BOETDBQF7JFX$POUSPMMFS%FNP