Slide 1

Slide 1 text

ݹ͖ྑ͖ sendAction ॴ ༑ଠ @tokorom iOS App Programer potatotips-26

Slide 2

Slide 2 text

ॴ༑ଠ @tokorom (ϑϦʔλʔʣ potatotipsӡӦ૭ޱ / potatotipsΛओ࠵͍͚ͨͩΔձࣾ͞Μืूதʂ

Slide 3

Slide 3 text

UIApplication - sendAction

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

UIApplication - sendAction NEW! iOS 9 Ͱ ྲྀ੕ ͷ͝ͱ͘ݱΕͨ ࠷ڧ ͷ function !?

Slide 6

Slide 6 text

UIApplication - sendAction iPhone OS 2 ͔Β ͘͝ ී௨ ʹଘࡏ͢Δ ͋·Γ ࢖ΘΕͳ͍ ΍ͭ

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

Responder Chain (in UIKit)

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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)

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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