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

古き良きsendAction (in potatotips #26)

tokorom
February 17, 2016

古き良きsendAction (in potatotips #26)

UIApplicationのsendActionを見直そう

tokorom

February 17, 2016
Tweet

More Decks by tokorom

Other Decks in Technology

Transcript

  1. ݹ͖ྑ͖ sendAction
    ॴ ༑ଠ @tokorom

    iOS App Programer
    potatotips-26

    View Slide

  2. ॴ༑ଠ
    @tokorom (ϑϦʔλʔʣ

    potatotipsӡӦ૭ޱ / potatotipsΛओ࠵͍͚ͨͩΔձࣾ͞Μืूதʂ

    View Slide

  3. UIApplication - sendAction

    View Slide

  4. UIApplication - sendAction
    •࣮ࡍʹ࢖͍ͬͯΔਓ͸Ͳͷ͘Β͍ʁ
    •ͦ΋ͦ΋ଘࡏΛ஌͍ͬͯΔʁ
    •ʢUIControlͷ΄͏͸ͨ·ʹݟΔ͚Ͳ…ʣ
    •ʢ࢖͍ͬͯΔͷΛ͋Μ·Γݟͨ͜ͱͳ͍ʣ

    View Slide

  5. UIApplication - sendAction
    NEW!
    iOS 9
    Ͱ

    ྲྀ੕
    ͷ͝ͱ͘ݱΕͨ

    ࠷ڧ
    ͷ
    function !?

    View Slide

  6. UIApplication - sendAction
    iPhone OS 2
    ͔Β

    ͘͝
    ී௨
    ʹଘࡏ͢Δ

    ͋·Γ
    ࢖ΘΕͳ͍
    ΍ͭ

    View Slide

  7. // hoge: ΛൃՐ
    let app = UIApplication.sharedApplication()
    app.sendAction("hoge:", to: xxx, from: sender, forEvent: nil)
    // hoge:
    func hoge(sender: AnyObject) {
    print("hoge!!")
    }
    αϯϓϧίʔυ
    UIApplication - sendAction

    View Slide

  8. UIApplication - sendAction
    •ग़ͨΑɺจࣈྻࢦఆʂ
    •Objective-C෩selectorࢦఆ͕ݹष͍
    •࢖͍ॴ͋Δͷʁ
    •RxSwiftͱ͔࢖͏΄͏͕Α͘ͳ͍ʁ
    app.sendAction("hoge:", to: xxx, from: sender, forEvent: nil)
    ͓͓ΉͶ
    ਖ਼ղ

    View Slide

  9. Responder Chain (in UIKit)

    View Slide

  10. Responder Chain (in UIKit)
    •Ԟ·ͬͨ֊૚ͰൃՐ
    •֊૚ͷͲ͜Ͱ΋ड͚ΒΕΔ
    •DelegateͷΑ͏ʹreceiverΛड͚
    ౉͢ඞཁ͕ͳ͍
    •ଞखஈͰಉ͡ߏ଄Λ࣮ݱ͢Δͷ͸
    ೉͍͠

    View Slide

  11. Responder Chain (in UIKit)
    app.sendAction("hoge:", to: xxx, from: sender, forEvent: nil)
    app.sendAction("hoge:", to: , from: sender, forEvent: nil)
    app.sendAction("hoge:", to: nil, from: sender, forEvent: nil)

    View Slide

  12. Responder Chain (in UIKit)
    UITabBarController
    UIViewController
    UITabBarController
    UIViewController
    UIViewController
    UIViewController

    View Slide

  13. Responder Chain (in UIKit)
    UITabBarController
    UIViewController
    UITabBarController
    UIViewController
    UIViewController
    UIViewController
    UITableView
    UITableViewCell
    UIView
    UIButton

    View Slide

  14. sendActionͷྑ͍ͱ͜Ζ
    •Responder Chainͳૄ݁߹ͳ࢓૊ΈͰը໘ߏ੒
    ͕มΘͬͯ΋ར༻Ͱ͖Δ
    •CocoaͷࠜװͱͳΔ࢓૊ΈͷͨΊྲྀߦʹࠨӈ͞
    Εͳ͍

    View Slide

  15. sendActionͷμϝͳͱ͜Ζ
    •ΠϯλʔϑΣʔε͕ݹ͍
    •จࣈྻࢦఆ
    •selector??
    •Ҿ਺ʹಛఆͷObjectΛ౉ͮ͠Β͍

    View Slide

  16. ৽͍͠ΠϯλʔϑΣʔεͰϥοϐϯά
    // hoge: ΛൃՐ
    HogeEvent(hoge: hoge).fireFrom(self.view)
    // hoge:
    func hoge(sender: AnyObject) {
    guard let hoge: Hoge =ɹContext.valueFor(sender) else {
    return
    }
    print("hoge: \(hoge)")
    }

    View Slide

  17. ·ͱΊ
    •UIApplicationͷsendAction͸৔߹ʹΑͬͯ͸༗

    •ݹ͖ྑ͖ػೳ͕ͩը໘ߏ੒͕ෳࡶͳݱ୅Ͱͦ͜
    ར༻Ձ஋͕͋Δ
    •ੲ͔Β͋Δػೳʹ΋ҙ֎ͱ࢖͑Δ΋ͷ͕຾ͬͯ
    ͍Δ͔΋ʁ

    View Slide

  18. More Information
    Yuta ToKoRo
    iOS App Programer
    Twitter @tokorom
    http://www.tokoro.me/

    View Slide