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

「文化を調和させる」 をやってみる Try “Blending Culture”

「文化を調和させる」 をやってみる Try “Blending Culture”

■ Special Thanks To:
- Daniel H Steinberg
Twitter(https://twitter.com/dimsumthinking
Web Site(http://dimsumthinking.com/

■ Sample repo
- https://github.com/masashi-sutou/BlendingCulturesExample

Masashi-Sutou

March 11, 2016
Tweet

More Decks by Masashi-Sutou

Other Decks in Programming

Transcript

  1. ʮจԽΛௐ࿨ͤ͞Δʯ
    Λ΍ͬͯΈΔ
    5SZl#MFOEJOH$VMUVSFz


    View full-size slide

  2. ·ͣ࠷ॳʹʜɻ

    View full-size slide

  3. ுΓ੾Γ͗͢·ͨ͠
    ݁ߏͳεϥΠυ਺Ͱ͢
    ςϯϙΑ͘ਐΊ͍͖ͯ·͢ʂʂ

    View full-size slide

  4. ʮจԽΛௐ࿨ͤ͞Δʯͱ͸ʁ
    w USZ 4XJGUͷ̍೔໨ʹߦΘΕͨ
    %BOJFM)4UFJOCFSHࢯͷൃද
    ʮ#MFOEJOH$VMUVSFʯͷ͜ͱ
    w 4XJGUΒ͍͠.7$Ϟσϧͷ
    5BCMF7JFX$POUSPMMFSͷ࡞Γ
    ํΛ঺հ͍ͯͨ͠
    w USZ4XJGU͔ͩΒɺ5SZ
    l#MFOEJOH$VMUVSFzͯ͜ͱ
    Ͱɺ౰೔Λࢥ͍ग़ͯࣗ͠෼Ͱ
    ΍ͬͯΈΔ Ҿ༻ݩɿIUUQEFWDMBTTNFUIPEKQTNBSUQIPOFUSZTXJGUTUEBZQN

    View full-size slide

  5. – Daniel H Steinberg
    l4XJGUͰΞϓϦέʔγϣϯΛॻ͘ͱ͍͏͜ͱ͸0CKFDUJWF$
    Ͱॻ͔ΕͨΞϓϦέʔγϣϯΛͨͩ4XJGUʹॻ͖׵͑Δ͚ͩ
    Ͱͳ͘ɺ4XJGUͷಛ௃΍఩ֶΛड͚ೖΕΔඞཁ͕͋Γ·͢ɻ
    ͜ͷߨԋͰ͸ɺඪ४తͳ.7$Ͱߏ੒͞ΕͨςʔϒϧϏϡʔ
    Λ࢖༻ͨ͠ΞϓϦέʔγϣϯΛ4XJGUʹॻ͖׵͑Δͱ͜Ζ͔
    Β࢝·ΓɺΑΓ4XJGUΒ͍͠ίʔυʹ͢ΔͨΊʹɺؔ਺ܕϓ
    ϩάϥϛϯάɺΦϒδΣΫτࢦ޲ϓϩάϥϛϯάɺσβΠϯ
    ύλʔϯɺϓϩτίϧࢦ޲ϓϩάϥϛϯάͷߟ͑ํΛద༻͠
    ͍͖ͯ·͢ɻz
    ʮจԽΛௐ࿨ͤ͞Δʯͱ͸ʁ

    View full-size slide

  6. ௐ࿨͍ͤͨ͞จԽͨͪ
    w 0010CKFDU0SJFOUFE1SPHSBNNJOH ΦϒδΣΫτ
    ࢦ޲ϓϩάϥϛϯά

    w 1011SPUPDPM0SJFOUFE1SPHSBNNJOH ϓϩτίϧࢦ
    ޲ϓϩάϥϛϯά

    w '1'VODUJPOBM1SPHSBNNJOH ϑΝϯΫγϣφϧϓϩ
    άϥϛϯά

    w .7$.PEFM7JFX$POUSPMMFS ϞσϧɾϏϡʔɾίϯ
    τϩʔϥʔ


    View full-size slide

  7. #MFOEJOH$VMUVSF
    $POUSPMMFS
    .PEFM 7JFX
    001
    101 '1

    View full-size slide

  8. #MFOEJOH$VMUVSF4BNQMF
    $POUSPMMFS
    .PEFM 7JFX

    View full-size slide

  9. $POUSPMMFS
    7JFX
    )BOE
    #MFOEJOH$VMUVSF4BNQMF

    View full-size slide

  10. $POUSPMMFS
    )BOE
    .BJO
    TUPSZCPBSE
    #MFOEJOH$VMUVSF4BNQMF

    View full-size slide

  11. )BOE
    )BOE7$
    .BJO
    TUPSZCPBSE
    #MFOEJOH$VMUVSF4BNQMF

    View full-size slide

  12. 'JSTU%FNP
    w USZ4XJGU౰೔ͷൃදͰ͸
    %FDL $BSEΫϥεͷιʔε͸
    ެ։͞Εͣ
    w ಠࣗͰߟ࣮͑૷ͯ͠Έͨਓ͕
    2JJUBʹ౤ߘ͍ͯͨ͠ͷͰࢀߟ
    ʹͨ͠
    w IUUQRJJUBDPNTV@LJUFNT
    DBFGBBGF

    View full-size slide

  13. )BOE7$TXJGU
    खࡳͷ௥Ճมߋલ
    import UIKit
    class HandVC: UITableViewController {
    private let hand = Hand()
    override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationItem.leftBarButtonItem = editButtonItem()
    }
    @IBAction private func addNewCard(sender: UIBarButtonItem) {
    if hand.numberOfCards < 5 {
    hand.addNewCardAtIndex(0)
    tableView.insertRowsAtIndexPaths([NSIndexPath(forRow: 0, inSection: 0)],
    withRowAnimation: .Fade)
    }
    }

    View full-size slide

  14. )BOE7$TXJGU
    खࡳͷ௥Ճมߋޙ

    import UIKit
    class HandVC: UITableViewController {
    private let hand = Hand()
    override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationItem.leftBarButtonItem = editButtonItem()
    }
    @IBAction private func addNewCard(sender: UIBarButtonItem) {
    if hand.numberOfCards < 5 {
    hand.addNewCardAtIndex(0)
    insertTopRow()
    }
    }
    private func insertTopRow() {
    tableView.insertRowsAtIndexPaths([NSIndexPath(forRow: 0, inSection: 0)],
    withRowAnimation: .Fade)
    }

    View full-size slide

  15. )BOE7$TXJGU
    खࡳͷຕ਺ͱදࣔ

    // MARK: - Table view data source
    override func tableView(tableView: UITableView,
    numberOfRowsInSection section: Int) -> Int {
    return hand.numberOfCards
    }
    override func tableView(tableView: UITableView,
    cellForRowAtIndexPath indexPath: NSIndexPath)
    -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier(“cardCell",
    forIndexPath: indexPath)
    let card = hand.cardAtPosition(indexPath.row)
    cell.textLabel?.text = card.rank.description
    cell.textLabel?.textColor = card.color
    cell.detailTextLabel?.text = card.suit.description
    return cell
    }

    View full-size slide

  16. )BOE7$TXJGU
    खࡳͷ࡟আมߋલ

    override func tableView(tableView: UITableView,
    commitEditingStyle editingStyle:UITableViewCellEditingStyle,
    forRowAtIndexPath indexPath: NSIndexPath) {
    if editingStyle == .Delete {
    hand.deleteCardAtIndex(indexPath.row)
    tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
    }
    }

    View full-size slide

  17. )BOE7$TXJGU
    खࡳͷ࡟আมߋޙ

    override func tableView(tableView: UITableView,
    commitEditingStyle editingStyle: UITableViewCellEditingStyle,
    forRowAtIndexPath indexPath: NSIndexPath) {
    if editingStyle == .Delete {
    hand.deleteCardAtIndex(indexPath.row)
    deleteRowAtIndexPath(indexPath)
    }
    }
    private func deleteRowAtIndexPath(indexPath: NSIndexPath) {
    tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
    }

    View full-size slide

  18. )BOE7$TXJGU
    खࡳͷҠಈ

    override func tableView(tableView: UITableView
    moveRowAtIndexPath sourceIndexPath: NSIndexPath,
    toIndexPath destinationIndexPath: NSIndexPath) {
    hand.moveCard(sourceIndexPath.row, toIndex: destinationIndexPath.row)
    }

    View full-size slide

  19. )BOETXJGU
    खࡳͷϞσϧΫϥε

    import UIKit
    class Hand {
    private let deck = Deck()
    private var cards = [Card]()
    var numberOfCards: Int {
    return cards.count
    }
    func cardAtPosition(index: Int) -> Card {
    return cards[index]
    }

    View full-size slide

  20. )BOETXJGU
    खࡳͷϞσϧΫϥε௥Ճɾ࡟আɾҠಈ

    func addNewCardAtIndex(index: Int) {
    insertCard(deck.nextCard(), atIndex: index)
    }
    private func insertCard(card: Card, atIndex index: Int) {
    cards.insert(card, atIndex: index)
    }
    func deleteCardAtIndex(index: Int) {
    cards.removeAtIndex(index)
    }
    func moveCard(fromIndex: Int, toIndex: Int) {
    let cardToMove = cards[fromIndex]
    deleteCardAtIndex(fromIndex)
    insertCard(cardToMove, atIndex: toIndex)
    }

    View full-size slide

  21. )BOETXJGU
    खࡳͷϞσϧΫϥε௥Ճɾ࡟আɾҠಈ

    func addNewCardAtIndex(index: Int) {
    insertCard(deck.nextCard(), atIndex: index)
    }
    private func insertCard(card: Card, atIndex index: Int) {
    cards.insert(card, atIndex: index)
    }
    func deleteCardAtIndex(index: Int) {
    cards.removeAtIndex(index)
    }
    func moveCard(fromIndex: Int, toIndex: Int) {
    let cardToMove = cards[fromIndex]
    deleteCardAtIndex(fromIndex)
    insertCard(cardToMove, atIndex: toIndex)
    }

    View full-size slide

  22. )BOE
    )BOE7$
    .BJO
    TUPSZCPBSE
    #MFOEJOH$VMUVSF4BNQMF

    View full-size slide

  23. – Daniel H Steinberg
    l͜͜·Ͱ͸ೃછΈ͕͋Γ·͔͢ʁ͜ΕͰຬ଍Ͱ͔͢ʁ
    ͔͜͜Β෼ͰͲ͏ల։Ͱ͖Δ͔ͷ͓࿩Λ͢Δɻ
    ͜Ε͕࠷ળͱ͸ݴΘͳ͍͕ɺ͜Μͳͷ͸೗Կͱ͍͏͜ͱͰz
    ͔͜͜ΒɺจԽΛௐ࿨ͤ͞Δ

    View full-size slide

  24. $MBTTUPB4USVDU

    View full-size slide

  25. )BOETXJGU
    खࡳͷϞσϧߏ଄ମ

    import UIKit
    struct Hand {
    private let deck = Deck()
    private var cards = [Card]()
    var numberOfCards: Int {
    return cards.count
    }
    func cardAtPosition(index: Int) -> Card {
    return cards[index]
    }

    View full-size slide

  26. 4XJGUͷDMBTTͱTUSVDUͷҧ͍
    w l.PEFM$MBTTͰ͸ͳ͘
    7BMVF5ZQFʹ͠·͢z%BOJFM
    )4UFJOCFSH
    w খͯ͘͞୯७ͳσʔλΛΧϓ
    ηϧԽ͍ͨ͠৔߹
    w ࢀর౉͠ΑΓ஋౉͠ ίϐʔ
    ͕
    ͍͍৔߹
    w ܧঝ͕ඞཁͳ͍৔߹
    http://qiita.com/mini_house/items/22b7b88794b9f8a32381

    View full-size slide

  27. ߏ଄ମͷ஋Λॻ͖׵͑Δ
    ؔ਺ʹ͸ɺNVUBUJOH͕ඞཁ

    View full-size slide

  28. )BOETXJGU
    खࡳͷϞσϧߏ଄ମ௥Ճɾ࡟আɾҠಈ

    mutating func addNewCardAtIndex(index: Int) {
    insertCard(deck.nextCard(), atIndex: index)
    }
    private mutating func insertCard(card: Card, atIndex index: Int) {
    cards.insert(card, atIndex: index)
    }
    mutating func deleteCardAtIndex(index: Int) {
    cards.removeAtIndex(index)
    }
    mutating func moveCard(fromIndex: Int, toIndex: Int) {
    let cardToMove = cards[fromIndex]
    deleteCardAtIndex(fromIndex)
    insertCard(cardToMove, atIndex: toIndex)
    }

    View full-size slide

  29. )BOE7$TXJGU
    ϞσϧͷએݴΛఆ਺͔Βม਺΁
    import UIKit
    class HandVC: UITableViewController {
    private var hand = Hand()
    override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationItem.leftBarButtonItem = editButtonItem()
    }
    @IBAction private func addNewCard(sender: UIBarButtonItem) {
    if hand.numberOfCards < 5 {
    hand.addNewCardAtIndex(0)
    tableView.insertRowsAtIndexPaths([NSIndexPath(forRow: 0, inSection: 0)],
    withRowAnimation: .Fade)
    }
    }

    View full-size slide

  30. -FU`TFMJNJOBUFNVUBUJOH

    View full-size slide

  31. )BOETXJGU
    खࡳͷߏ଄ମ௥ՃͷNVUBUJOHΛ֎͢

    mutating func addNewCardAtIndex(index: Int) {
    insertCard(deck.nextCard(), atIndex: index)
    }
    func addNewCardAtIndex(index: Int) -> Hand {
    return insertCard(deck.nextCard(), atIndex: index)
    }

    View full-size slide

  32. )BOETXJGU
    खࡳͷߏ଄ମ௥ՃͰΠϯελϯεΛฦ͢

    private func insertCard(card: Card, atIndex index: Int) -> Hand {
    var mutableCards = cards
    mutableCards.insert(card, atIndex: index)
    return Hand(deck: deck, cards: mutableCards)
    }

    View full-size slide

  33. )BOETXJGU
    खࡳͷߏ଄ମ௥ՃͰΠϯελϯεΛฦ͢

    private func insertCard(card: Card, atIndex index: Int) -> Hand {
    var mutableCards = cards
    mutableCards.insert(card, atIndex: index)
    return Hand(deck: deck, cards: mutableCards)
    }

    View full-size slide

  34. 4XJGUͷߏ଄ମ͸ϓϩύςΟΛ
    Ҿ਺ʹ΋ͭΠχγϟϥΠβ͕
    ࣗಈੜ੒͞ΕΔ

    View full-size slide

  35. )BOETXJGU
    खࡳͷϞσϧΫϥε

    import UIKit
    struct Hand {
    private var deck = Deck()
    private var cards = [Card]()
    var numberOfCards: Int {
    return cards.count
    }
    func cardAtPosition(index: Int) -> Card {
    return cards[index]
    }

    View full-size slide

  36. ͔͠͠ɺࠓճ͸EFDL͕ఆ਺ͳ
    ͷͰΧελϜΠχγϟϥΠβ
    ͰରԠ͢Δ

    View full-size slide

  37. )BOETXJGU
    खࡳͷϞσϧΫϥε

    import UIKit
    struct Hand {
    private let deck = Deck()
    private var cards = [Card]()
    init() {
    }
    private init (deck: Deck, cards: [Card]) {
    self.cards = cards
    }
    var numberOfCards: Int {
    return cards.count
    }

    View full-size slide

  38. )BOETXJGU
    खࡳͷߏ଄ମ௥ՃͰΠϯελϯεΛฦ͢

    private func insertCard(card: Card, atIndex index: Int) -> Hand {
    var mutableCards = cards
    mutableCards.insert(card, atIndex: index)
    return Hand(deck: deck, cards: mutableCards)
    }

    View full-size slide

  39. )BOE7$TXJGU
    खࡳͷ௥ՃΠϯελϯεΛड͚औΔ

    import UIKit
    class HandVC: UITableViewController {
    private var hand = Hand()
    override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationItem.leftBarButtonItem = editButtonItem()
    }
    @IBAction private func addNewCard(sender: UIBarButtonItem) {
    if hand.numberOfCards < 5 {
    hand = hand.addNewCardAtIndex(0)
    insertTopRow()
    }
    }

    View full-size slide

  40. )BOE7$TXJGU
    खࡳͷ࡟আͱҠಈ௥Ճͱಉ༷ʹ͍ͨ͠

    override func tableView(tableView: UITableView,
    commitEditingStyle editingStyle: UITableViewCellEditingStyle,
    forRowAtIndexPath indexPath: NSIndexPath) {
    if editingStyle == .Delete {
    hand = hand.deleteCardAtIndex(indexPath.row)
    deleteRowAtIndexPath(indexPath)
    }
    }
    override func tableView(tableView: UITableView,
    moveRowAtIndexPath sourceIndexPath: NSIndexPath,
    toIndexPath destinationIndexPath: NSIndexPath) {
    hand = hand.moveCard(sourceIndexPath.row, toIndex: destinationIndexPath.row)
    }

    View full-size slide

  41. )BOETXJGU
    खࡳͷߏ଄ମ࡟আͰΠϯελϯεΛฦ͢

    mutating func deleteCardAtIndex(index: Int) {
    cards.removeAtIndex(index)
    }
    func deleteCardAtIndex(index: Int) -> Hand {
    var mutableCards = cards
    mutableCards.removeAtIndex(index)
    return Hand(deck: deck, cards: mutableCards)
    }

    View full-size slide

  42. ௥Ճ΍࡟আͱಉ༷ʹ
    Ҡಈ΋NVUBUJOHΛ֎͚͢Ͳ
    ͜͜ͰจԽΛௐ࿨ͤ͞Δ

    View full-size slide

  43. 'VODUJPOBM1SPHSBNNJOH
    ϑΝϯΫγϣφϧϓϩάϥϛϯά


    View full-size slide

  44. )BOETXJGU
    खࡳͷߏ଄ମҠಈͰΠϯελϯεΛฦ͢

    func moveCard(fromIndex: Int, toIndex: Int) -> Hand {
    return deleteCardAtIndex(fromIndex)
    .insertCard(cards[fromIndex], atIndex: toIndex)
    }
    mutating func moveCard(fromIndex: Int, toIndex: Int) {
    let cardToMove = cards[fromIndex]
    deleteCardAtIndex(fromIndex)
    insertCard(cardToMove, atIndex: toIndex)
    }

    View full-size slide


  45. deleteCardAtIndex(fromIndex)ͷΠϯελϯε
    insertCard(cards[fromIndex], atIndex: toIndex)ͷΠϯελϯε
    cards[fromIndex] = ߏ଄ମͷϓϩύςΟ

    View full-size slide

  46. – Daniel H Steinberg
    l͜ΕͰεϚΠϧʹͳΒͳ͍ͳΒ
    +BWBͳΓ3VCZͳΓ΍Ε͹͍͍ͱࢥ͍·͢Αʁz

    View full-size slide

  47. .PWFUPB$VTUPN$FMM

    View full-size slide

  48. .PEJpFE.77.
    .PEFM7JFX7JFX.PEFM


    View full-size slide

  49. $BSE$FMMTXJGU
    खࡳΛදࣔ͢ΔΧελϜηϧʢ7JFXʣ

    import UIKit
    class CardCell: UITableViewCell {
    @IBOutlet private weak var suitLabel: UILabel!
    @IBOutlet private weak var rankLabel: UILabel!
    override func awakeFromNib() {
    super.awakeFromNib()
    }
    func fillWith(card: Card) {
    rankLabel.textColor = card.color
    rankLabel.text = card.rank.description
    suitLabel.text = card.suit.description
    }
    }

    View full-size slide

  50. )BOE7$TXJGU
    खࡳΛදࣔ͢Δίϯτϩʔϥʔ

    override func tableView(tableView: UITableView,
    cellForRowAtIndexPath indexPath: NSIndexPath)
    -> UITableViewCell {
    guard let cell = tableView
    .dequeueReusableCellWithIdentifier("cardCell",
    forIndexPath: indexPath) as? CardCell else {
    fatalError("Could not create CardCell")
    }
    cell.fillWith(hand.cardAtPosition(indexPath.row))
    return cell
    }

    View full-size slide

  51. HVBSEMFUFMTFͷಛ௃
    w 4XJGU͔Β௥Ճ͞Εͨɺ஋ͷόϦσʔγϣϯνΣοΫΛॻ͖΍͘͢͢Δߏจ
    w ΞϯϥοϓͱOJMνΣοΫΛಉ࣌ʹߦ͑ɺΞϯϥοϓ͞Εͨม਺͸HVBSEจΛൈ͚ͨޙͰ΋
    ࢖༻Մ
    w HVBSEจͷFMTFઅͷதͰ͸ɺSFUVSO CSFBL DPOUJOVF UISPXͷͲΕ͔ΛߦΘͳ͍ͱί
    ϯύΠϧΤϥʔ
    http://qiita.com/mishimay/items/75fb0958f33079ff0e8a

    func show(message: String?) {
    guard let theMessage = message else {
    return
    }
    print(theMessage) // Ξϯϥοϓͨ͠ม਺Λ࢖͏͜ͱ͕Ͱ͖Δ
    }

    View full-size slide

  52. )BOE7$TXJGU
    खࡳΛදࣔ͢Δίϯτϩʔϥʔ

    override func tableView(tableView: UITableView,
    cellForRowAtIndexPath indexPath: NSIndexPath)
    -> UITableViewCell {
    guard let cell = tableView
    .dequeueReusableCellWithIdentifier("cardCell",
    forIndexPath: indexPath) as? CardCell else {
    fatalError("Could not create CardCell")
    }
    cell.fillWith(hand.cardAtPosition(indexPath.row))
    return cell
    }

    View full-size slide

  53. TVCTDSJQUΛ࢖͏
    w ഑ྻ΍ࣙॻͷཁૉʹ௚઀ΞΫηε͢ΔॲཧΛɺΫϥε΍ߏ଄ମʹࣗ෼ͰఆٛͰ͖Δ
    w ࠓճ͸ɺߏ଄ମʹͨ͠)BOEͷ$BSETͷཁૉʹΞΫηε͢ΔॲཧΛTVCTDSJQUͰه
    ड़͢Δ

    struct Hand {
    private let deck = Deck()
    private var cards = [Card]()
    var numberOfCards: Int {
    return cards.count
    }
    subscript(index: Int) -> Card {
    return cards[index]
    }

    View full-size slide

  54. )BOE7$TXJGU
    खࡳΛදࣔ͢Δίϯτϩʔϥʔ

    override func tableView(tableView: UITableView,
    cellForRowAtIndexPath indexPath: NSIndexPath)
    -> UITableViewCell {
    guard let cell = tableView
    .dequeueReusableCellWithIdentifier("cardCell",
    forIndexPath: indexPath) as? CardCell else {
    fatalError("Could not create CardCell")
    }
    cell.fillWith(hand.cardAtPosition(indexPath.row))
    return cell
    }
    cell.fillWith(hand[indexPath.row])
    return cell
    }

    View full-size slide

  55. )BOE
    )BOE7$
    .PEFM7JFX7JFX.PEFM

    $BSE$FMM

    View full-size slide

  56. )BOE
    )BOE7$
    .PEFM7JFX7JFX.PEFM

    $BSE$FMM

    View full-size slide

  57. – Daniel H Steinberg
    lօϞσϧΛ෼͔͍ͬͯΔঢ়ଶͰΑ͘ͳ͘ݟ͑Δʁ
    ͜Ε͔Βྑ͘ͳΔɻz

    View full-size slide

  58. 5BLFUIF%BUB4PVSDFPVUPG
    UIF5BCMF7JFX$POUSPMMFS

    View full-size slide

  59. )BOE
    )BOE7$
    %BUB4PVSDFΛ7JFX$POUSPMMFS
    ͔ΒऔΓग़͢

    %BUB4PVSDF

    View full-size slide

  60. %BUB4PVSDFTXJGU
    7$͔ΒϞσϧґଘͷॲཧΛग़͢

    import UIKit
    class DataSource: NSObject, UITableViewDataSource {
    private var hand = Hand()
    func addItemTo(tableView: UITableView) {}
    func tableView(tableView: UITableView,
    numberOfRowsInSection section: Int) -> Int {}
    func tableView(tableView: UITableView,
    cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {}
    func tableView(tableView: UITableView,
    commitEditingStyle editingStyle: UITableViewCellEditingStyle,
    forRowAtIndexPath indexPath: NSIndexPath) {}
    func tableView(tableView: UITableView,
    moveRowAtIndexPath fromIndexPath: NSIndexPath,
    toIndexPath: NSIndexPath) {}
    func insertTopRowIn(tableView: UITableView) {}
    func deleteRowAtIndexPath(indexPath: NSIndexPath, from tableView: UITableView) {}
    }

    View full-size slide

  61. )BOE7$TXJGU
    7$ͰEBUB4PVSDFΛࢦఆ͢Δ

    import UIKit
    class HandVC: UITableViewController {
    private var dataSource = DataSource()
    override func viewDidLoad() {
    super.viewDidLoad()
    tableView.dataSource = dataSource
    self.navigationItem.leftBarButtonItem = editButtonItem()
    }
    @IBAction private func addNewCard(sender: UIBarButtonItem) {
    dataSource.addItemTo(tableView)
    }
    }

    View full-size slide

  62. )BOE
    )BOE7$

    %BUB4PVSDF

    View full-size slide

  63. %BUB4PVSDFTXJGU
    7$͔ΒϞσϧґଘͷॲཧΛग़͢

    import UIKit
    class DataSource: NSObject, UITableViewDataSource {
    private var hand = Hand()
    func addItemTo(tableView: UITableView) {}
    func tableView(tableView: UITableView,
    numberOfRowsInSection section: Int) -> Int {}
    func tableView(tableView: UITableView,
    cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {}
    func tableView(tableView: UITableView,
    commitEditingStyle editingStyle: UITableViewCellEditingStyle,
    forRowAtIndexPath indexPath: NSIndexPath) {}
    func tableView(tableView: UITableView,
    moveRowAtIndexPath fromIndexPath: NSIndexPath,
    toIndexPath: NSIndexPath) {}
    func insertTopRowIn(tableView: UITableView) {}
    func deleteRowAtIndexPath(indexPath: NSIndexPath, from tableView: UITableView) {}
    }

    View full-size slide

  64. – Daniel H Steinberg
    l͜ΕΒ͸ͪΐͬͱҧ͏ɻ
    Ҿ্͖͛Δɻ
    1SPUPDPMΛ࢖͍·͢ɻz

    View full-size slide

  65. 1SPUPDPM0SJFOUFE
    1SPHSBNNJOH
    ϓϩτίϧࢦ޲ϓϩάϥϛϯά

    View full-size slide

  66. )BOE
    )BOE7$

    %BUB4PVSDF
    4PVSDF5ZQF

    View full-size slide

  67. 4PVSDF5ZQFTXJGU
    ϓϩτίϧͰҾ্͖͛Δ

    import UIKit
    protocol SourceType: UITableViewDataSource {
    func insertTopRowIn(tableView: UITableView)
    func deleteRowAtIndexPath(indexPath: NSIndexPath, from tableView: UITableView)
    }
    extension SourceType {
    func insertTopRowIn(tableView: UITableView) {
    tableView.insertRowsAtIndexPaths([NSIndexPath(forRow: 0, inSection: 0)],
    withRowAnimation: .Fade)
    }
    func deleteRowAtIndexPath(indexPath: NSIndexPath, from tableView: UITableView) {
    tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
    }
    }

    View full-size slide

  68. %BUB4PVSDFTXJGU
    %BUB4PVSDFΛ4PVSDF5ZQFʹ४ڌ

    import UIKit
    class DataSource: NSObject, UITableViewDataSource, SourceType {
    private var hand = Hand()
    func addItemTo(tableView: UITableView) {}
    func tableView(tableView: UITableView,
    numberOfRowsInSection section: Int) -> Int {}
    func tableView(tableView: UITableView,
    cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {}
    func tableView(tableView: UITableView,
    commitEditingStyle editingStyle: UITableViewCellEditingStyle,
    forRowAtIndexPath indexPath: NSIndexPath) {}
    func tableView(tableView: UITableView,
    moveRowAtIndexPath fromIndexPath: NSIndexPath,
    toIndexPath: NSIndexPath) {}
    }

    View full-size slide

  69. QSPUPDPMFYUFOTJPOͱ͸ʁ
    w QSPUPDPMʢΠϯλϑΣʔεͷఆٛʣΛ֦ு͠ɺϝιουͷ࣮૷Λ௥Ճ͢Δػೳ
    w ศརͳQSPUPDPMFYUFOTJPO͕ͩɺ֨ೲܕϓϩύςΟΛ࣋ͭ͜ͱ͕Ͱ͖ͳ͍

    protocol MyProtocol {
    func hoge()
    }
    extension MyProtocol {
    func hoge() {
    print("hoge")
    }
    }
    class MyClass: MyProtocol {
    }
    let myInstance = MyClass()
    myInstance.hoge() // hoge ͱग़ྗ͞ΕΔ

    View full-size slide

  70. )BOE
    )BOE7$

    %BUB4PVSDF
    4PVSDF5ZQF
    %BUB5ZQF

    View full-size slide

  71. )BOETXJGU
    %BUB5ZQF΁Ҿ্͖͛Δલʹ

    import UIKit
    struct Hand {
    private let deck = Deck()
    private var cards = [Card]()
    init() {}
    private init (deck: Deck, cards: [Card]) {}
    subscript(index: Int) -> Card {}
    var numberOfCards: Int {}
    func addNewCardAtIndex(index: Int) -> Hand {}
    private func insertCard(card: Card, atIndex index: Int) -> Hand {}
    func deleteCardAtIndex(index: Int) -> Hand {}
    func moveCard(fromIndex: Int, toIndex: Int) -> Hand {}
    }

    View full-size slide

  72. )BOETXJGU
    %BUB5ZQF΁Ҿ্͖͛Δલʹ

    import UIKit
    struct Hand {
    private let deck = Deck()
    private var cards = [Card]()
    init() {}
    private init (deck: Deck, cards: [Card]) {}
    subscript(index: Int) -> Card {}
    var numberOfItems: Int {}
    func addNewItemAtIndex(index: Int) -> Hand {}
    private func insertItem(card: Card, atIndex index: Int) -> Hand {}
    func deleteItemAtIndex(index: Int) -> Hand {}
    func moveItem(fromIndex: Int, toIndex: Int) -> Hand {}
    }

    View full-size slide

  73. %BUB5ZQFTXJGU
    %BUB5ZQF΁Ҿ্͖͛Δ

    import UIKit
    protocol DataType {
    var numberOfItems: Int { get }
    func addNewItemAtIndex(index: Int) -> Self
    func deleteItemAtIndex(index: Int) -> Self
    func moveItem(fromIndex: Int, toIndex: Int) -> Self
    }

    View full-size slide

  74. %BUB5ZQFTXJGU
    %BUB5ZQFʹ४ڌͨ͠΋ͷΛฦ͢

    import UIKit
    protocol DataType {
    var numberOfItems: Int { get }
    func addNewItemAtIndex(index: Int) -> Self
    func deleteItemAtIndex(index: Int) -> Self
    func moveItem(fromIndex: Int, toIndex: Int) -> Self
    }

    View full-size slide

  75. – Daniel H Steinberg
    l)BOEΛฦ͍ͯͨ͠ͷΛ4FMGͰฦ͢Α͏ʹ͢Δɻ
    ʢ4FMG͸ʣ%BUB5ZQFʹ४ڌ͍ͯ͠Δऀࣗ਎ɻz

    View full-size slide

  76. )BOETXJGU
    )BOE͸%BUB5ZQFʹ४ڌ

    import UIKit
    struct Hand : DataType {
    private let deck = Deck()
    private var cards = [Card]()
    init() {}
    private init (deck: Deck, cards: [Card]) {}
    subscript(index: Int) -> Card {}
    var numberOfItems: Int {}
    func addNewItemAtIndex(index: Int) -> Hand {}
    private func insertItem(card: Card, atIndex index: Int) -> Hand {}
    func deleteItemAtIndex(index: Int) -> Hand {}
    func moveItem(fromIndex: Int, toIndex: Int) -> Hand {}
    }

    View full-size slide

  77. )BOE
    )BOE7$

    %BUB4PVSDF
    4PVSDF5ZQF
    %BUB5ZQF

    View full-size slide

  78. 4PVSDF5ZQFTXJGU
    %BUB5ZQFΛϓϩύςΟʹએݴ

    import UIKit
    protocol SourceType: UITableViewDataSource {
    var dataObject: DataType { get set }
    func insertTopRowIn(tableView: UITableView)
    func deleteRowAtIndexPath(indexPath: NSIndexPath, from tableView: UITableView)
    }
    extension SourceType {
    func insertTopRowIn(tableView: UITableView) {
    tableView.insertRowsAtIndexPaths([NSIndexPath(forRow: 0, inSection: 0)],
    withRowAnimation: .Fade)
    }
    func deleteRowAtIndexPath(indexPath: NSIndexPath, from tableView: UITableView) {
    tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
    }
    }

    View full-size slide

  79. %BUB4PVSDFTXJGU
    )BOEΛ%BUB5ZQFͰड͚Δ

    import UIKit
    class DataSource: NSObject, UITableViewDataSource, SourceType {
    var dataObject: DataType = Hand()
    func addItemTo(tableView: UITableView) {
    if dataObject.numberOfItems < 5 {
    dataObject = dataObject.addNewItemAtIndex(0)
    insertTopRowIn(tableView)
    }
    }
    }

    View full-size slide

  80. %BUB4PVSDFTXJGU
    )BOE΋HVBSEͰ߹Θͤͯ൑ఆ͢Δ

    func tableView(tableView: UITableView,
    cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    guard let cell = tableView
    .dequeueReusableCellWithIdentifier("cardCell",
    forIndexPath: indexPath)
    as? CardCell, hand = dataObject as? Hand else {
    fatalError("Could not create CardCell or Hand instance")
    }
    cell.fillWith(hand[indexPath.row])
    return cell
    }

    View full-size slide

  81. – Daniel H Steinberg
    l͍͖ͭͯͯ·͢ʁ
    4UPQͬͯݴͬͯ͘Εͯ΋͍͍Ͱ͢Αʁz

    View full-size slide

  82. – Daniel H Steinberg
    lଞʹσʔλιʔε͔ΒϓϧΞ΢τग़དྷͳ͍͔ʁz

    View full-size slide

  83. %BUB4PVSDFTXJGU

    import UIKit
    class DataSource: NSObject, UITableViewDataSource, SourceType {
    var dataObject: DataType = Hand()
    func addItemTo(tableView: UITableView) {
    if dataObject.numberOfItems < 5 {
    dataObject = dataObject.addNewItemAtIndex(0)
    insertTopRowIn(tableView)
    }
    }

    View full-size slide

  84. – Daniel H Steinberg
    l͜Ε͸ʢ͜͜ʹʣ͋Δ΂͖Ͱ͠ΐ͏͔ʁz

    View full-size slide

  85. 4PVSDF5ZQFTXJGU
    4PVSDF5ZQFʹ൑ఆ஋Λ࣋ͨͤΔ

    import UIKit
    protocol SourceType: UITableViewDataSource {
    var dataObject: DataType { get set }
    var conditionForAdding: Bool { get }
    func insertTopRowIn(tableView: UITableView)
    func deleteRowAtIndexPath(indexPath: NSIndexPath, from tableView: UITableView)
    }
    extension SourceType {
    func insertTopRowIn(tableView: UITableView) {
    tableView.insertRowsAtIndexPaths([NSIndexPath(forRow: 0, inSection: 0)],
    withRowAnimation: .Fade)
    }
    func deleteRowAtIndexPath(indexPath: NSIndexPath, from tableView: UITableView) {
    tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
    }
    }

    View full-size slide

  86. 4PVSDF5ZQFTXJGU
    4PVSDF5ZQFʹ൑ఆ஋Λ࣋ͨͤΔ

    import UIKit
    protocol SourceType: UITableViewDataSource {
    var dataObject: DataType { get set }
    var conditionForAdding: Bool { get }
    func insertTopRowIn(tableView: UITableView)
    func deleteRowAtIndexPath(indexPath: NSIndexPath,
    from tableView: UITableView)
    }
    extension SourceType {
    func addItemTo(tableView: UITableView) {
    if conditionForAdding {
    dataObject = dataObject.addNewItemAtIndex(0)
    insertTopRowIn(tableView)
    }
    }
    func insertTopRowIn(tableView: UITableView) {
    tableView.insertRowsAtIndexPaths([NSIndexPath(forRow: 0, inSection: 0)],
    withRowAnimation: .Fade)
    }
    func deleteRowAtIndexPath(indexPath: NSIndexPath, from tableView: UITableView) {
    tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
    }
    }

    View full-size slide

  87. %BUB4PVSDFTXJGU
    ਺ͷ൑ఆͷΈߦ͏

    import UIKit
    class DataSource: NSObject, UITableViewDataSource, SourceType {
    var dataObject: DataType = Hand()
    var conditionForAdding :Bool {
    return dataObject.numberOfItems < 5
    }
    import UIKit
    class DataSource: NSObject, UITableViewDataSource, SourceType {
    var dataObject: DataType = Hand()
    func addItemTo(tableView: UITableView) {
    if dataObject.numberOfItems < 5 {
    dataObject = dataObject.addNewItemAtIndex(0)
    insertTopRowIn(tableView)
    }
    }

    View full-size slide

  88. )BOE
    )BOE7$

    )BOE%BUB4PVSDF
    4PVSDF5ZQF
    %BUB5ZQF
    %BUB4PVSDF

    View full-size slide

  89. /PXQVTI)BOESFGFSFODF
    EPXOJOUPUIFTVCDMBTT

    View full-size slide

  90. )BOE%BUB4PVSDFTXJGU
    %BUB4PVSDFͷαϒΫϥε࡞੒

    import UIKit
    class HandDataSource: DataSource {
    init() {
    super.init(dataObject: Hand())
    }
    override func tableView(tableView: UITableView,
    cellForRowAtIndexPath indexPath: NSIndexPath)
    -> UITableViewCell {
    guard let cell = tableView
    .dequeueReusableCellWithIdentifier("cardCell",
    forIndexPath: indexPath)
    as? CardCell, hand = dataObject as? Hand else {
    return UITableViewCell()
    }
    cell.fillWith(hand[indexPath.row])
    return cell
    }
    override var conditionForAdding: Bool {
    return dataObject.numberOfItems < 5
    }
    }

    View full-size slide

  91. )BOE%BUB4PVSDFTXJGU
    %BUB4PVSDFͷαϒΫϥε࡞੒

    import UIKit
    class HandDataSource: DataSource {
    init() {
    super.init(dataObject: Hand())
    }
    override func tableView(tableView: UITableView,
    cellForRowAtIndexPath indexPath: NSIndexPath)
    -> UITableViewCell {
    guard let cell = tableView
    .dequeueReusableCellWithIdentifier("cardCell",
    forIndexPath: indexPath)
    as? CardCell, hand = dataObject as? Hand else {
    return UITableViewCell()
    }
    cell.fillWith(hand[indexPath.row])
    return cell
    }
    override var conditionForAdding: Bool {
    return dataObject.numberOfItems < 5
    }
    }

    View full-size slide

  92. %BUB4PVSDFTXJGU
    %BUB4PVSDF͔ΒϞσϧґଘΛͳ͘͢

    import UIKit
    class DataSource: NSObject, UITableViewDataSource, SourceType {
    var dataObject: DataType
    var conditionForAdding :Bool {
    return false
    }
    import UIKit
    class DataSource: NSObject, UITableViewDataSource, SourceType {
    var dataObject: DataType = Hand()
    var conditionForAdding :Bool {
    return dataObject.numberOfItems < 5
    }

    View full-size slide

  93. %BUB4PVSDFTXJGU
    %BUB4PVSDFͷΠχγϟϥΠβ࡞੒

    import UIKit
    class DataSource: NSObject, UITableViewDataSource, SourceType {
    var dataObject: DataType
    var conditionForAdding :Bool {
    return false
    }
    init(dataObject: A) {
    self.dataObject = dataObject
    }

    View full-size slide

  94. )BOE7$TXJGU
    7$Ͱ)BOE%BUB4PVSDFΛࢦఆ

    import UIKit
    class HandVC: UITableViewController {
    private var dataSource = HandDataSource()
    override func viewDidLoad() {
    super.viewDidLoad()
    tableView.dataSource = dataSource
    self.navigationItem.leftBarButtonItem = editButtonItem()
    }
    @IBAction private func addNewCard(sender: UIBarButtonItem) {
    dataSource.addItemTo(tableView)
    }
    }

    View full-size slide

  95. – Daniel H Steinberg
    lͯ͞ɺԿΛ͠·͔ͨ͠ʁ
    ͍ΖΜͳ؆ૉԽ͠·ͨ͠ɻ
    มߋ͠ͳ͍ίʔυΛ֎ʹ௥͍ग़͠·ͨ͠ɻz

    View full-size slide

  96. )BOE
    )BOE7$

    )BOE%BUB4PVSDF
    4PVSDF5ZQF
    %BUB5ZQF
    %BUB4PVSDF

    View full-size slide

  97. – Daniel H Steinberg
    lมߋ͢Δ΋ͷΛԼʹ࣋ͬͯདྷ·ͨ͠ɻz

    View full-size slide

  98. )BOE
    )BOE7$

    )BOE%BUB4PVSDF
    4PVSDF5ZQF
    %BUB5ZQF
    %BUB4PVSDF

    View full-size slide

  99. #MFOEJOH$VMUVSF
    $POUSPMMFS
    .PEFM 7JFX
    001
    101 '1

    View full-size slide

  100. 5SZl#MFOEJOH$VMUVSFzΛ΍ͬ
    ͯΈͨײ૝
    w ൃද࣌ؒʹΑΓɺ΍Ήͳ͘লུ͞Εͯ͠·ͬͨ෦෼
    ͕͋Δͷʹ΍ͬͯΈͯؾͮ͘ɻ
    w ͳͷͰɺࣗ෼ͰखΛಈ͔͠ͳ͕Β࣮ࡍʹ΍ͬͯΈΔ
    ͜ͱΛڧ͓͘קΊ͢Δ
    w αϯϓϧͰ͸ͳ͘ɺ΋͏গ͠ػೳͷଟ͍ϓϩδΣΫ
    τʹಋೖ͢ΔͱɺͲͷΑ͏ʹιʔε͕มԽ͢Δͷ͔ɺ
    ·ͩมԽͤ͟ΔΛಘͳ͍ͷ͔ɺUSZͯ͠Έ͍ͨɻ

    View full-size slide

  101. ͦΕͧΕͷ%FNP࣌఺ͷιʔε͸ɺ
    ԼهͷϦϙδτϦʹϒϥϯνΛ੾ͬ
    ͯอଘͨ͠
    IUUQTHJUIVCDPNNBTBTIJTVUPV
    #MFOEJOH$VMUVSFT&YBNQMF

    View full-size slide

  102. ࢀߟࢿྉ
    http://niwatako.hatenablog.jp/entry/2016/03/02/160011
    ɾʮUSZ4XJGUจԽΛௐ࿨ͤ͞ΔUSZTXJGUDPOG%BZʯ
    ɾʮUSZ4XJGU࠷଎Ϩϙʔτ೔໨ޕޙUSZTXJGUDPOGʯ
    http://dev.classmethod.jp/smartphone/tryswift-1st-day-pm/
    ɾʮUSZ4XJGU೔໨#MFOEJOH$VMUVSFTzͷ಺༰Λ
    αϯϓϧΞϓϦʹىͯ͜͠Έͨʯ
    http://qiita.com/su_k/items/42c29a0e136faa3f9e08
    ɾʮ#MFOEJOH$VMUVSFʯUSZ4XJGU
    Daniel Steinberg @dimsumthinking

    View full-size slide

  103. ࢀߟࢿྉ
    http://qiita.com/mishimay/items/75fb0958f33079ff0e8a
    ɾʮ4XJGUͰ௥Ճ͞ΕͨHVBSEͷ͍͍ͱ͜Ζʯ
    ɾʮ4XJGUͷ4VCTDSJQUʹ͍ͭͯʯ
    http://qiita.com/happy_ryo/items/72b68859ed8ace9f5fb4
    ɾʮ4XJGUͷQSPUPDPMFYUFOTJPOͰNJYJOతͳ΋ͷΛ
    ࣮ݱ͢Δʯ
    http://qiita.com/sagaraya/items/5e73501ff7a3f0c502c0
    ɾʮ4XJGUͷΫϥεͱߏ଄ମͷ࢖͍෼͚ʹ͍ͭͯͷϝϞʯ
    http://qiita.com/mini_house/items/22b7b88794b9f8a32381

    View full-size slide