20180220_iOSLT_Swiftとオブジェクト間の通知のパターン

E45f9c343d90c74554c65c89c6f861bc?s=47 shtnkgm
February 20, 2018

 20180220_iOSLT_Swiftとオブジェクト間の通知のパターン

E45f9c343d90c74554c65c89c6f861bc?s=128

shtnkgm

February 20, 2018
Tweet

Transcript

  1. SwiftͱΦϒδΣΫτؒͷ௨஌ͷύλʔϯ 2018/2/20 @shtnkgm

  2. ࿩͢͜ͱ SwiftͱΦϒδΣΫτؒͷ௨஌ͷύλʔϯʹ͍ͭͯߟ͑·͢ 1. ௨஌ํ๏ͷઃܭʹ͍ͭͯ 2. ΞϯνύλʔϯΛؚΊͨҎԼͷ5ͭͷ௨஌ύλʔϯ 3. ύλʔϯͷൺֱͱ࢖͍෼͚ʹ͍ͭͯ

  3. ௨஌ͱ͸ ΦϒδΣΫτؒͷʮ௨஌ʯͱ͸ΦϒδΣΫτؒͷϝοηʔδͷ΍ ΓͱΓΛҙຯ͠·͢ɻ

  4. ͳͥ௨஌ํ๏ͷઃܭ͕ඞཁ͔ • ৑௕ͳίʔυͷഉআɺ࠶ར༻ੑ޲্͍ͤͨ͞ • ίʔυΛ੹຿ʹԠͯ͡ෳ਺ͷΦϒδΣΫτ΁෼ׂ͍ͨ͠ • ෳ਺ͷΦϒδΣΫτΛѻ͏ͨΊɺͦͷ௨஌ํ๏ͷઃܭ͕ඞཁ

  5. ྫ୊ɿViewͱModel Modelͷσʔλߋ৽ͷ׬ྃΛView΁ͲͷΑ͏ʹ௨஌͢Δʁ ※Prensenter΍ViewModelͳͲΞʔΩςΫνϟͷ࿩͸͜͜Ͱ͸ߟ͑ͳ͍΋ͷͱ͠·͢ɻ

  6. 5ͭͷ௨஌ύλʔϯ 1. ॥؀ࢀরύλʔϯʢΞϯνύλʔϯʣ 2. Delegateύλʔϯʢऑࢀর+ϙϦϞʔϑΟζϜʣ 3. NotificationCenterύλʔϯ 4. KVOύλʔϯʢKey-Value Observing:

    Ωʔ஋؂ࢹʣ 5. Closure Callbackύλʔϯ ※SwiftͰඪ४αϙʔτ͞Ε͍ͯͳ͍ɺRxSwift΍BondͳͲͷσʔλόΠϯσΟϯάύλʔϯ͸ର৅֎
  7. 5ͭͷ௨஌ύλʔϯ 1. ॥؀ࢀরύλʔϯʢΞϯνύλʔϯʣ 2. Delegateύλʔϯʢऑࢀর+ϙϦϞʔϑΟζϜʣ 3. NotificationCenterύλʔϯ 4. KVOύλʔϯʢKey-Value Observing:

    Ωʔ஋؂ࢹʣ 5. Closure Callbackύλʔϯ
  8. 1. ॥؀ࢀরύλʔϯʢΞϯνύλʔϯʣ • ผΦϒδΣΫτͷϝιουΛ࣮ߦ͢Δʹ͸ɺͦͷΦϒδΣΫτ ͷࢀরΛ͍࣋ͬͯΕ͹ྑ͍ • ͭ·ΓΦϒδΣΫτؒͰ૬ޓʹ௨஌Λ͢Δʹ͸͓ޓ͍ͷࢀরΛ ͍࣋ͬͯΕ͹ྑ͍

  9. class View { // ˒ ModelΦϒδΣΫτ΁ͷࢀর var model: Model =

    Model() func receiveUIEvent() { // ModelͷviewϓϩύςΟʹࣗ਎Ληοτ model.view = self // 2. σʔλͷߋ৽ΛModelʹ௨஌ model.updateData() } // 5. UIͷߋ৽ func updateUI() { print("\(model.data)") } }
  10. class Model { // ˒ ViewΦϒδΣΫτ΁ͷࢀর var view: View? var

    data: Int = 0 // 3. σʔλͷߋ৽ func updateData() { data += 1 // 4. View΁σʔλͷߋ৽׬ྃΛ௨஌ view?.updateUI() } }
  11. ͜ͷίʔυ͸ಈ͚͘Ͳ...

  12. ॥؀ࢀর໰୊͕͋Δ • ਖ਼ৗʹಈ࡞͢Δ͕ɺʮ॥؀ࢀরʯ(strong reference cycle)ͱ͍ ͏໰୊͋Γ • ࢀরؔ܎͕॥؀͍ͯ͠Δ৔߹ɺΦϒδΣΫτ͸ϝϞϦ͔Βղ์ ͞Εͳ͍ʢ=ϝϞϦϦʔΫʣ •

    ϝϞϦϦʔΫ͕૿͑ΔͱύϑΥʔϚϯε͕མͪɺ࠷ѱΞϓϦ͕ Ϋϥογϡ͢Δ
  13. ิ଍: iOSͷϝϞϦ؅ཧํࣜʹ͍ͭͯʢ1/2ʣ • iOSͰ͸ϝϞϦ؅ཧΛࢀরΧ΢ϯλ(Reference Counting)ͱ͍͏ ํࣜͰߦ͍ͬͯΔ • ࢀর͞ΕΔ͝ͱʹ+1ɺࢀর͕ͳ͘ͳͬͨ࣌఺Ͱ-1

  14. ิ଍: iOSͷϝϞϦ؅ཧํࣜʹ͍ͭͯʢ2/2ʣ • ࢀরΦϒδΣΫτ͕ͳ͍৔߹ɺࢀরΧ΢ϯλ͕0ʹͳΔ • OS͸ͦͷΦϒδΣΫτΛϝϞϦ͔Β։์ͯ͠΋ྑ͍ͱ൑அ

  15. ॥؀ࢀরύλʔϯΛվળ͍ͨ͠

  16. 5ͭͷ௨஌ύλʔϯ 1. ॥؀ࢀরύλʔϯʢΞϯνύλʔϯʣ 2. Delegateύλʔϯʢऑࢀর+ϙϦϞʔϑΟζϜʣ 3. NotificationCenterύλʔϯ 4. KVOύλʔϯʢKey-Value Observing:

    Ωʔ஋؂ࢹʣ 5. Closure Callbackύλʔϯ
  17. 2. Delegateύλʔϯʢऑࢀর+ϙϦϞʔϑΟζϜʣ • weakΩʔϫʔυΛ͚ͭΔ͜ͱͰɺʮऑࢀরʯʢweak referenceʣ͢Δ • ௨ৗͷʮڧࢀরʯͱҟͳΓɺࢀরΧ΢ϯλ͕૿͑ͳ͍

  18. ऑࢀরͷϓϩύςΟͰ͸ࢀরઌͷΦϒδΣΫτ͕ղ์͞Εɺnil͕ ୅ೖ͞ΕΔՄೳੑ͕͋ΔͨΊɺΦϓγϣφϧܕͰఆٛ // weakΩʔϫʔυͰऑࢀর weak var view: View?

  19. ॥؀ࢀর໰୊͸ղܾͨ͠

  20. ·ͩվྑͷ༨஍͋Γ • ViewͱModel͕ʮີ݁߹ʯ(tight coupling)Ͱ͋Δ • ີ݁߹ͳઃܭ͸มߋʹऑ͘ɺ࠶ར༻΋ͮ͠Β͍ • ͜͜Ͱݴ͏มߋʹऑ͍ͱ͍͏ͷ͸ɺ࢓༷มߋ͕ೖͬͨ৔߹ʹม ߋՕॴ͕ଟ͘ͳΔͱ͍͏ҙຯ

  21. SecondView͕ModelΛ࢖͏࢓༷มߋΛ૝ఆ class Model { // View → SecondViewʹมߋ͕ඞཁʢModel͸Viewʹґଘ͍ͯ͠Δʣ weak var

    view: View? var data: Int = 0 func updateData() { data += 1 view?.updateUI() } }
  22. ີ݁߹໰୊ͷղܾ • Model͕Viewʹґଘ͠ͳ͍ॻ͖ํʹ͢Δ • ΑΓந৅తͳΠϯλϑΣʔεʹґଘͤ͞ΔΑ͏ʹ͢Δ • Model͕ඞཁͱ͢Δந৅తͳΠϯλϑΣʔεͱ͸Կ͔

  23. ந৅తͳΠϯλϑΣʔε • ʮupdateUIϝιου͕࣮ߦͰ͖Δ͜ͱʯͷΈ • updateUIϝιου͕࣮ߦͰ͖ΔΫϥεͰ͋Ε͹ͲΜͳΫϥεͰ ΋ྑ͍ • ͜ͷந৅తͳΠϯλϑΣʔεΛද͢ํ๏ͷ1ͭͱͯ͠ɺSwiftͰ ͸ϓϩτίϧ͕͋Δ ʢJavaʹ͓͚Δinterfaceʹ͍ۙ֓೦ʣ

  24. updateUIϝιουΛ࣋ͭͱ͍͏֓೦ΛϓϩτίϧͰ࣮૷ // ViewProtocolʹ४ڌ͢Δܕ͸updateUI()ͱ͍͏ϝιουΛ࣋ͭ protocol ViewProtocol { func updateUI() }

  25. ϓϩτίϧ͕ܕͱͯ͠ѻ͑Δ • ΠϯελϯεԽ͸Ͱ͖ͳ͍͕ɺܕͱͯ͠ѻ͑Δ protocol ViewProtocol: class { func updateUI() }

    class Model { // ViewͰͳ͘ViewProtocolʹґଘ weak var view: ViewProtocol? var data: Int = 0 func updateData() { data += 1 view?.updateUI() } }
  26. ۩৅ΫϥεΛϓϩτίϧʹ४ڌͤ͞Δ // ViewProtocolʹ४ڌ͢Δ͜ͱΛએݴ class View: ViewProtocol { var model: Model

    = Model() func receiveUIEvent() { model.view = self model.updateData() } // ViewProtocolʹ४ڌͨ͠ϝιου func updateUI() { print("\(model.data)") } }
  27. ิ଍: Class-Only Protocols protocol ViewProtocol: class { func updateUI() }

    ্هͷίʔυྫͰ͸ɺViewProtocol͸classΛܧঝ͍ͤͯ͞·͢ɻ classΛܧঝ͢Δͱɺͦͷϓϩτίϧ͸Ϋϥεʹ͔͠ద༻Ͱ͖ͳ͘ ͳΓ·͢ɻ
  28. ͳͥclassܧঝ͕ඞཁ͔ • ModelͷviewϓϩύςΟ͸weakʢऑࢀরʣͰఆٛ͞Ε͍ͯΔͨ ΊɺΫϥεʢࢀরܕʣͰ͋Δඞཁ͋Γ ʢߏ଄ମ΍ྻڍମ͸஋ܕͰ͋ΔͨΊNGʣ • ViewProtocol͕ΫϥεʢࢀরܕʣͰ͋Δ͜ͱΛ໌ࣔ͢ΔͨΊʹ classΛܧঝ͢Δ class Model

    { // weak͕͍͍ͭͯΔͷͰViewProtocol͸ࢀরܕͰ͋Δඞཁ͕͋Δ weak var view: ViewProtocol?
  29. ґଘؔ܎ΛղফͰ͖ͨ • ͜ΕͰModel͕Viewʹґଘ͠ͳ͍ίʔυʹͳͬͨ • ͜Ε͸ʮϙϦϞʔϑΟζϜʯͷҰྫʹ΋ͳ͍ͬͯΔ ʢϓϩτίϧ͕ϙϦϞʔϑΟζϜͷ࣮ݱखஈͷͻͱͭʣ

  30. ϙϦϞʔϑΟζϜʢpolymorphism: ଟଶੑʣ ಈతʹϝιουʹΑͬͯݺͼग़͞ΕΔΦϒδΣΫτ͕มΘΓɺͦ ͷΦϒδΣΫτʹΑͬͯৼΔ෣͍͕มΘΔͱ͍͏ੑ࣭

  31. ࠓճͷྫͱϙϦϞʔϑΟζϜ • Model͸viewϓϩύςΟʹର͠updateUIϝιουΛ࣮ߦ • viewϓϩύςΟ͕Viewͳͷ͔SecondViewͳͷ͔͸஌Βͳ͍ ʢviewϓϩύςΟ͕ෳ਺ͷܕʹͳΓ͏Δ:ϙϦϞʔϑΟζϜʣ • ࣮ߦΦϒδΣΫτʹΑͬͯupdateUIϝιουͷ࣮૷͕ҟͳΔ ʢViewΛߋ৽ or

    SecondViewΛߋ৽ʣ
  32. UIKitͱσϦήʔτύλʔϯ • UIKitϑϨʔϜϫʔΫͰ͸UITableViewDelegateɺ UIPickerViewDelegateͳͲ਺ଟ͘ͷΦϒδΣΫτͰ͜ͷύλʔ ϯΛ࠾༻ • σϦήʔτύλʔϯʹ͓͚ΔϙϦϞʔϑΟζϜͷੑ࣭Λ׆͔͢ ͜ͱͰɺ࠶ར༻ੑͷߴ͍UI෦඼Λఏڙ

  33. ϝϦσϝ • !ϓϩτίϧʹΑΓ࣮૷͢΂͖ϝιου͕໌֬ • "௨৴׬ྃͷ௨஌ͷΈͳͲɺγϯϓϧͳ௨஌ͷ৔߹ʹ͸هड़ί ετͱݟ߹Θͳ͍ (σϦήʔτϓϩύςΟͷ࣮૷ɺϓϩτίϧఆٛɺϓϩτίϧ΁ ͷ४ڌ) • "Մಡੑ͕ൺֱత௿͍

  34. 5ͭͷ௨஌ύλʔϯ 1. ॥؀ࢀরύλʔϯʢΞϯνύλʔϯʣ 2. Delegateύλʔϯʢऑࢀর+ϙϦϞʔϑΟζϜʣ 3. NotificationCenterύλʔϯ 4. KVOύλʔϯʢKey-Value Observing:

    Ωʔ஋؂ࢹʣ 5. Closure Callbackύλʔϯ
  35. 3. NotificationCenterύλʔϯ • NotificationCenterΫϥεΛར༻ͨ͠௨஌ͷύλʔϯ • NotificationCenter͸ड৴ొ࿥ͨ͠ΦϒδΣΫτʹର͠৘ใΛϒ ϩʔυΩϟετ͢Δ • ௨஌ΠϯλϑΣʔε͸௨஌໊ʢจࣈྻʣͷΈ •

    ಉ͡௨஌໊ΛผͷΦϒδΣΫτ͔Β΋ૹ৴Ͱ͖ΔͨΊɺଟରଟ ͷ௨஌Λ࣮ݱ
  36. NotificationCenterͷTips ௨஌໊͸Notification.NameΛextensionͰ֦ு͠ɺstaticϓϩύς ΟͰఆ͓ٛͯ͘͠ͱར༻͠΍͍͢ // ௨஌໊Λొ࿥ extension Notification.Name { static let

    updateDataNotification = Notification.Name("updateDataNotification") }
  37. ड৴ొ࿥ / ૹ৴ͷ࢓ํ //ɹ௨஌ͷड৴ొ࿥ʢupdateDataNotificationͷ௨஌Λड৴ͨ͠ΒɺupdateUIϝιουΛ࣮ߦʣ NotificationCenter.default.addObserver(self, selector: #selector(updateUI), name: .updateDataNotification, object:

    nil) // ௨஌ͷૹ৴ʢupdateDataNotificationͷ௨஌Λૹ৴ʣ NotificationCenter.default.post(name: .updateDataNotification, object: nil)
  38. Model͔ΒView΁௨஌͢Δྫ class View { var model: Model = Model() init()

    { // ௨஌ͷड৴ొ࿥ʢupdateDataNotificationͷ௨஌Λड৴ͨ͠ΒɺupdateUIϝιουΛ࣮ߦʣ NotificationCenter.default.addObserver(self, selector: #selector(updateUI), name: .updateDataNotification, object: nil) } func receiveUIEvent() { model.updateData() } @objc func updateUI() { print("\(model.data)") } }
  39. class Model { var data: Int = 0 func updateData()

    { data += 1 // ௨஌ͷૹ৴ʢupdateDataNotificationͷ௨஌Λૹ৴ʣ NotificationCenter.default.post(name: .updateDataNotification, object: nil) } }
  40. ௨஌ͷड৴ղআʹ͍ͭͯʢremoveObserverʣ • ௨஌ͷड৴ղআΛద੾ʹߦΘͳ͍ͱ։์͞ΕͨΦϒδΣΫτʹ ௨஌Λૹͬͯ͠·͏ʢ࣮ߦ࣌Ϋϥογϡʣ • iOS9Ҏ߱Ͱ͸deinit࣌ʹࣗಈͰ࣮ߦ // deinitͰͷड৴ղআ͸ෆཁ deinit {

    NotificationCenter.default.removeObserver(self, name: .updateDataNotification, object: nil) }
  41. ิ଍:SelectorͰͷϝιου࣮ߦʹ͍ͭͯ Selector͸࣮ߦ࣌ʹݺͼग़͢ϝιου͕ܾఆ͢ΔɺObjective-Cํ ࣜͷಈతͳݺͼग़͠Λߦ͏ͨΊɺupdateUIϝιουʹ͸@objcଐੑ Λ͚ͭΔ @objc func updateUI() { print("\(model.data)") }

  42. ϝϦσϝ • !௨஌໊Ͱ؆୯ʹ௨஌Λ࣮૷Ͱ͖Δʢ௨஌จࣈྻͷΈ͕Πϯλ ϑΣʔεͰૄ݁߹ʣ • !NରNͷ௨஌͕ඞཁͳ৔߹΍௨஌͍ͨ͠ΦϒδΣΫτؒʹ௚઀ ͷࢀরؔ܎͕ͳ͍৔߹ʹ༗ޮ • "ଟ༻͢ΔͱॲཧͷྲྀΕ͕௥͍ͮΒ͍ʢεύήοςΟϓϩάϥ ϜʹͳΔՄೳੑʣ

  43. 5ͭͷ௨஌ύλʔϯ 1. ॥؀ࢀরύλʔϯʢΞϯνύλʔϯʣ 2. Delegateύλʔϯʢऑࢀর+ϙϦϞʔϑΟζϜʣ 3. NotificationCenterύλʔϯ 4. KVOύλʔϯʢKey-Value Observing:

    Ωʔ஋؂ࢹʣ 5. Closure Callbackύλʔϯ
  44. 4. KVOύλʔϯʢKey-Value Observing: Ωʔ஋؂ࢹʣ • KVO͸ϓϩύςΟ஋ͷมԽΛ؂ࢹ͢Δ࢓૊Έ • Objective-CͷϥϯλΠϜػೳΛར༻͍ͯ͠ΔͨΊɺ؂ࢹର৅ͷ ΦϒδΣΫτ͸NSObjectΛཁܧঝ •

    Swift4Ͱ͸ɺϓϩύςΟมߋ࣌ͷॲཧΛΫϩʔδϟʔͰॻ͚Δ Α͏ʹͳΓɺΑΓ࢖͍΍͍͢
  45. class View { var model: Model = Model() // ؂ࢹ༻ΦϒδΣΫτΛอ࣋͢Δ

    var observation: NSKeyValueObservation? init() { // modelͷdataϓϩύςΟΛKVOͰ؂ࢹ͢Δ observation = model.observe(\.data, options: [.new]) { model, change in // model.data͕มԽͨ͠৔߹ʹ࣮ߦ͞ΕΔΫϩʔδϟʔ if let newValue = change.newValue { print(newValue) } } } func receiveUIEvent() { model.updateData() } }
  46. // NSObjectΛܧঝ class Model: NSObject { // @objcͱdynamicΛ͚ͭΔ @objc dynamic

    var data: Int = 0 func updateData() { data += 1 } }
  47. ิ଍:dynamicΩʔϫʔυ • KVO͸Objective-CͷϥϯλΠϜػೳͰ͋ΔಈతσΟεύον ʢdynamic dispatchʣΛར༻ ʢ࣮ߦ࣌ʹಈతʹϓϩύςΟ͕ܾఆ͞ΕΔʣ • ΑͬͯϓϩύςΟʹ͸@objcͱdynamic͕ඞཁ @objc dynamic

    var data: Int = 0
  48. ϝϦσϝ • !WebKitͷWKWebViewͷϓϩύςΟͷதʹ͸ɺtitle΍urlɺ estimatedProgressͳͲɺKVOʹରԠͨ͠ϓϩύςΟ(key-value observing compliant)͕͋ΓɺKVOͱ૬ੑ͕ྑ͍ • "ߏ଄ମʢstructʣ͸NSObjectΛܧঝ͢Δ͜ͱ͕Ͱ͖ͳ͍ͨ ΊɺKVO͸ར༻Ͱ͖ͳ͍

  49. 5ͭͷ௨஌ύλʔϯ 1. ॥؀ࢀরύλʔϯʢΞϯνύλʔϯʣ 2. Delegateύλʔϯʢऑࢀর+ϙϦϞʔϑΟζϜʣ 3. NotificationCenterύλʔϯ 4. KVOύλʔϯʢKey-Value Observing:

    Ωʔ஋؂ࢹʣ 5. Closure Callbackύλʔϯ
  50. 5. Closure Callbackύλʔϯ ׬ྃޙͷॲཧΛΫϩʔδϟʔͰड͚औΓɺͦͷίʔϧόοΫ༻ͷ ΫϩʔδϟʔΛ࣮ߦ͢Δ͜ͱͰ௨஌͢Δύλʔϯ

  51. Ϋϩʔδϟʔ͸ؔ਺ͷΦϒδΣΫτ // Ϋϩʔδϟʔͷྫ let isEqual: (_ a: Int, _ b:

    Int) -> Bool = { a, b in return a == b } // ()Ͱ࣮ߦ isEqual(1, 1) // true isEqual(1, 2) // false
  52. class View { var model: Model = Model() func receiveUIEvent()

    { // ׬ྃޙͷॲཧΛΫϩʔδϟʔͰࢦఆ͢Δ // ຤ඌͷΫϩʔδϟʔͷҾ਺໊͸লུͰ͖Δʢtrailing closureه๏ʣ model.updateData { data in print(data) } } }
  53. class Model { var data: Int = 0 // ׬ྃޙͷॲཧΛҾ਺ͷΫϩʔδϟʔͰड͚औ࣮ͬͯߦ͢Δ

    func updateData(completion: (_ data: Int) -> Void) { data += 1 completion(data) } }
  54. ϝϦσϝ • !ݺͼग़͠ϝιουͷۙ͘ʹ׬ྃ࣌ͷॲཧΛॻ͚ΔͨΊɺίʔ υΛ௥͍΍͍͢ • "ͨͩ͠ෳ਺ͷඇಉظॲཧΛஞ࣮࣍ߦ͢Δ৔߹͸ɺΫϩʔδϟ ʔͷωετ͕ਂ͘ͳΒͳ͍Α͏ʹ஫ҙ func receiveUIEvent() {

    model.updateData(completion: { data in model.updateData(completion: { data in model.updateData(completion: { data in print(data) }) }) }) }
  55. UIKitͰͷར༻ ྫ͑͹UIAlertControllerͷUIAlertAction͸μΠΞϩάλοϓ࣌ͷॲ ཧΛΫϩʔδϟʔͰࢦఆ let alertAction = UIAlertAction(title: "OK", style: .default)

    { handler in // OKϘλϯλοϓ࣌ͷॲཧ print("OK͕λοϓ͞Ε·ͨ͠") }
  56. ௨஌ύλʔϯͷൺֱͱ࢖͍෼͚ • ௨஌ͷύλʔϯ͸͜Ε͕Ұ൪ྑ͍ͱ͍͏΋ͷ͸ͳ͍ • ༻్ʹԠͯ͡ద੾ʹ௨஌ͷύλʔϯΛબ୒ • ·ͣ͸௨஌ݩͱ௨஌ઌͷ਺ͷؔ܎ʹԠͯ͡௨஌ͷύλʔϯΛબ ୒

  57. ·ͱΊ 1. ॥؀ࢀরύλʔϯʢΞϯνύλʔϯʣ 2. Delegateύλʔϯʢऑࢀর+ϙϦϞʔϑΟζϜʣ 3. NotificationCenterύλʔϯ 4. KVOύλʔϯʢKey-Value Observing:

    Ωʔ஋؂ࢹʣ 5. Closure Callbackύλʔϯ
  58. ௨஌ͷύλʔϯ ௨஌ݩͱ௨஌ઌͷ਺ ϝϦοτ σϝϦοτ Delegate 1ɿ1 ϓϩτίϧʹΑΓ࣮૷͢΂͖ ௨஌ΠϯλϑΣʔε͕໌֬ɻ ௨஌͢Δϝιου͕1ͭͷ৔ ߹͸ɺهड़ྔʹݟ߹Θͳ

    ͍ɻ Notification NɿN ௚઀ͷࢀর͕ͳ͍ΦϒδΣΫ τؒͰ΋௨஌͕ՄೳɻΦϒδ ΣΫτ͕ؒૄ݁߹ɻ ଟ༻͢Δͱॲཧ͕௥͍ͮΒ ͘ͳΔɻάϩʔόϧͳείʔ ϓͰ௨஌Λߦ͏ͨΊɺϓϩ άϥϚ͕ҙਤ͠ͳ͍ॲཧ͕ ಈ͍ͯ͠·͏Մೳੑ͕͋Δɻ KVO 1ɿN WKWebViewͳͲKVOʹରԠ ͨ͠Ϋϥεͱ૬ੑ͕ྑ͍ɻ Objective-CͷϥϯλΠϜ͕ඞ ཁɻߏ଄ମͰ͸ར༻Ͱ͖ͳ ͍ɻ Closure Callback 1ɿ1 ॲཧͷґཔ෦෼ͱ׬ྃޙͷ ॲཧΛۙ͘ʹॻ͘͜ͱ͕Ͱ ͖ɺՄಡੑ͕ߴ͍ɻ ωετ૿͑͗͢΍callbackϝ ιουଟ͗͢ͰՄಡੑ☓ɻ
  59. SwiftͱΦϒδΣΫτؒͷ௨஌ͷύλʔϯ ͓ΘΓ