Upgrade to Pro — share decks privately, control downloads, hide ads and more …

つまづいた時のデバッグ術 / yumemi-swift-how-to-debug

つまづいた時のデバッグ術 / yumemi-swift-how-to-debug

0a7198a735873ed742be316848ec67d4?s=128

IshibaSeiko

May 15, 2020
Tweet

Transcript

  1. ͭ·͍ͮͨ࣌ͷσόοάज़ w ࣗݾ঺հ w എܠͱ໨త w σόοάज़ w QSJOUPCKFDU w

    #SFBLQPJOU "DUJPO w &YDFQUJPO#SFBLQPJOU w 7JFX%FCVH
  2. 2 ੴ৔ਗ਼ࢠ ͍͠͹͍ͤ͜ w J04ΤϯδχΞ w ࣮຿ܦݧ೥ ೥݄d  w

    Swiftେ޷͖ w (JUIVC • https://github.com/IshibaSeiko w 2JJUB • https://qiita.com/seikoseikou w 5XJUUFS • @seikoseikou w #MPH • https://seikoseikou.com
  3. 3 എܠͱ໨త wϓϩάϥϛϯά͸΄΅ະܦݧͰೖࣾͨͨ͠Ίɺ ʮσόοάʯΛ஌Βͳ͔ͬͨ wϏϧυͨ͠Βɺࢥ͍ඳ͍͍ͯͨڍಈʹͳΒͳ͔ͬͨʂ wόάௐࠪΛ೚͞Εͨʂ w Ͱ΋ɺݪҼͷௐ΂ํ͕Θ͔Βͳ͍ ϧʔΩʔୡʹɺσόοάज़Λڭ͍͑ͨʂ

  4. 4 αϯϓϧΞϓϦʹ͍ͭͯ ιʔείʔυ https://github.com/IshibaSeiko/DebugDemo ػೳ ϘλϯΛλοϓ͢Δͱɺ ੺৭ͷViewͱ੨৭ͷViewͷલޙ͕੾ΓସΘΔ ॲཧ @IBAction func

    didTapSwapButton(_ sender: UIButton) { view.bringSubviewToFront(view.subviews[1]) }
  5. 5 ࠓ೔঺հ͢Δσόοάज़ • print object w ஋Λ֬ೝ͍ͨ͠ • Breakpoint +

    Action w ॲཧΛ௨Δͨͼʹ஋Λ֬ೝ͍ͨ͠ • Exception Breakpoint w ΞϓϦΫϥογϡͷݪҼ͕஌Γ͍ͨ • View Debug w UI্ͷ໰୊Λ஌Γ͍ͨ
  6. 6 σόοάज़print object import UIKit class ViewController: UIViewController { override

    func viewDidLoad() { super.viewDidLoad() } @IBAction func didTapSwapButton(_ sender: UIButton) { view.bringSubviewToFront(view.subviews[1]) } } ϚδοΫφϯόʔ͔ͩΒɺ ͲͷView͕औಘ͞ΕΔ͔Θ͔Βͳ͍
  7. 7 Α͋͘Δ΍Γํ ໰୊఺ @IBAction func viewSwapButton(_ sender: UIButton) { view.bringSubviewToFront(view.subviews[1])

    print(view.subviews[1]) } • ֬ೝ͢ΔͨΊʹ͸Build͢Δඞཁ͕͋Δ • ػೳͱͯ͠ෆཁͳίʔυΛهड़͢Δ͜ͱͱͳΔ
  8. 8 σόοάज़print object ίϯιʔϧͰ஋Λ֬ೝ͢Δ

  9. 9 σόοάज़print object ੺৭ͷView͕औಘ͞Εͨ Ͱ΋ɺຖճpo͢Δͷɺ໘౗ʜ ϚδοΫφϯόʔ͔ͩΒɺ ͲͷView͕औಘ͞ΕΔ͔Θ͔Βͳ͍

  10. 10 σόοάज़Breakpoint + Action BreakpointʹActionΛ௥Ճ͠ɺϩάΛදࣔ͢Δ

  11. 11 σόοάज़Breakpoint + Action Ͱ΋ɺຖճ֬ೝ͢Δͷɺ໘౗ʜ ࣗಈͰϩά͕දࣔ͞ΕΔΑ͏ʹͳͬͨ ࣍͸όάΛൃੜͯ͠ΈΑ͏

  12. 12 σόοάज़Exception Breakpoint ࣄ৅ ϘλϯΛλοϓ͢Δͱɺ ΞϓϦ͕Ϋϥογϡ͢Δ ݪҼ͸ʜ

  13. 13 σόοάज़Exception Breakpoint AppDelegateͰΫϥογϡ͢Δ΍ͭ

  14. 14 σόοάज़Exception Breakpoint ྫ֎͕ൃੜͨ͠ՕॴͰϒϨʔΫ͢Δ

  15. 15 σόοάज़Exception Breakpoint ϘλϯΛλοϓ͢Δͱɺ ΞϓϦ͕Ϋϥογϡ͢Δ ഑ྻʹଘࡏ͠ͳ͍σʔλΛऔಘ͠Α͏ͱ͍ͯͨ͠ ࣍΋όάΛൃੜͤͯ͞ΈΔ

  16. 16 σόοάज़View Debug ࣄ৅ ϘλϯΛλοϓͰ͖ͳ͍ ݪҼ͸ʜ

  17. 17 σόοάज़View Debug Viewͷ֊૚Λ֬ೝ͢Δ

  18. 18 σόοάज़View Debug SwapϘλϯΑΓલ໘ʹɺ User Interaction Enabled͕Onʹͳ͍ͬͯΔView͕ ॏͳ͍ͬͯͨ ϘλϯΛλοϓͰ͖ͳ͍

  19. 19 ·ͱΊ • print object w ίϯιʔϧͰApo{֬ೝ͍ͨ͠ίʔυ}AΛೖྗ͢Δ • Breakpoint +

    Action w ઃఆͨ͠BreakpointΛμϒϧλοϓͯ͠actionΛ௥Ճ͢Δ • Exception Breakpoint w Breakpoint NavigatorࠨԼͷʮ ʯ͔Β Exception BreakpointΛ௥Ճ͢Δ • View Debug w Debug View HierarchyΛλοϓ͢Δ