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

E58d4a4aae067a3e1ca150bc0b5daef7?s=128

Masashi-Sutou

March 11, 2016
Tweet

Transcript

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

  2. ·ͣ࠷ॳʹʜɻ 

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

  4. ʮจԽΛௐ࿨ͤ͞Δʯͱ͸ʁ w USZ 4XJGUͷ̍೔໨ʹߦΘΕͨ %BOJFM)4UFJOCFSHࢯͷൃද ʮ#MFOEJOH$VMUVSFʯͷ͜ͱ w 4XJGUΒ͍͠.7$Ϟσϧͷ 5BCMF7JFX$POUSPMMFSͷ࡞Γ ํΛ঺հ͍ͯͨ͠

    w USZ4XJGU͔ͩΒɺ5SZ l#MFOEJOH$VMUVSFzͯ͜ͱ Ͱɺ౰೔Λࢥ͍ग़ͯࣗ͠෼Ͱ ΍ͬͯΈΔ Ҿ༻ݩɿIUUQEFWDMBTTNFUIPEKQTNBSUQIPOFUSZTXJGUTUEBZQN 
  5. – Daniel H Steinberg l4XJGUͰΞϓϦέʔγϣϯΛॻ͘ͱ͍͏͜ͱ͸0CKFDUJWF$ Ͱॻ͔ΕͨΞϓϦέʔγϣϯΛͨͩ4XJGUʹॻ͖׵͑Δ͚ͩ Ͱͳ͘ɺ4XJGUͷಛ௃΍఩ֶΛड͚ೖΕΔඞཁ͕͋Γ·͢ɻ ͜ͷߨԋͰ͸ɺඪ४తͳ.7$Ͱߏ੒͞ΕͨςʔϒϧϏϡʔ Λ࢖༻ͨ͠ΞϓϦέʔγϣϯΛ4XJGUʹॻ͖׵͑Δͱ͜Ζ͔ Β࢝·ΓɺΑΓ4XJGUΒ͍͠ίʔυʹ͢ΔͨΊʹɺؔ਺ܕϓ

    ϩάϥϛϯάɺΦϒδΣΫτࢦ޲ϓϩάϥϛϯάɺσβΠϯ ύλʔϯɺϓϩτίϧࢦ޲ϓϩάϥϛϯάͷߟ͑ํΛద༻͠ ͍͖ͯ·͢ɻz ʮจԽΛௐ࿨ͤ͞Δʯͱ͸ʁ 
  6. ௐ࿨͍ͤͨ͞จԽͨͪ w 0010CKFDU0SJFOUFE1SPHSBNNJOH ΦϒδΣΫτ ࢦ޲ϓϩάϥϛϯά  w 1011SPUPDPM0SJFOUFE1SPHSBNNJOH ϓϩτίϧࢦ ޲ϓϩάϥϛϯά

     w '1'VODUJPOBM1SPHSBNNJOH ϑΝϯΫγϣφϧϓϩ άϥϛϯά  w .7$.PEFM7JFX$POUSPMMFS ϞσϧɾϏϡʔɾίϯ τϩʔϥʔ 
  7. #MFOEJOH$VMUVSF $POUSPMMFS .PEFM 7JFX 001 101 '1 

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

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

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

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

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

    w IUUQRJJUBDPNTV@LJUFNT DBFGBBGF 
  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) } } 
  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) }
  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 }
  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) } }
  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) }
  18. )BOE7$TXJGU खࡳͷҠಈ  override func tableView(tableView: UITableView moveRowAtIndexPath sourceIndexPath: NSIndexPath,

    toIndexPath destinationIndexPath: NSIndexPath) { hand.moveCard(sourceIndexPath.row, toIndex: destinationIndexPath.row) }
  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] }
  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) }
  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) }
  22. )BOE )BOE7$ .BJO TUPSZCPBSE #MFOEJOH$VMUVSF4BNQMF 

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

  24. $MBTTUPB4USVDU 

  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] }
  26. 4XJGUͷDMBTTͱTUSVDUͷҧ͍ w l.PEFM$MBTTͰ͸ͳ͘ 7BMVF5ZQFʹ͠·͢z%BOJFM )4UFJOCFSH w খͯ͘͞୯७ͳσʔλΛΧϓ ηϧԽ͍ͨ͠৔߹ w ࢀর౉͠ΑΓ஋౉͠

    ίϐʔ ͕ ͍͍৔߹ w ܧঝ͕ඞཁͳ͍৔߹ http://qiita.com/mini_house/items/22b7b88794b9f8a32381 
  27. ߏ଄ମͷ஋Λॻ͖׵͑Δ ؔ਺ʹ͸ɺNVUBUJOH͕ඞཁ 

  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) }
  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) } } 
  30. NVUBUJOH

  31. -FU`TFMJNJOBUFNVUBUJOH 

  32. )BOETXJGU खࡳͷߏ଄ମ௥ՃͷNVUBUJOHΛ֎͢  mutating func addNewCardAtIndex(index: Int) { insertCard(deck.nextCard(), atIndex:

    index) } func addNewCardAtIndex(index: Int) -> Hand { return insertCard(deck.nextCard(), atIndex: index) }
  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) }
  34. )BOETXJGU खࡳͷߏ଄ମ௥ՃͰΠϯελϯεΛฦ͢  private func insertCard(card: Card, atIndex index: Int)

    -> Hand { var mutableCards = cards mutableCards.insert(card, atIndex: index) return Hand(deck: deck, cards: mutableCards) }
  35. 4XJGUͷߏ଄ମ͸ϓϩύςΟΛ Ҿ਺ʹ΋ͭΠχγϟϥΠβ͕ ࣗಈੜ੒͞ΕΔ 

  36. )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] }
  37. ͔͠͠ɺࠓճ͸EFDL͕ఆ਺ͳ ͷͰΧελϜΠχγϟϥΠβ ͰରԠ͢Δ 

  38. )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 }
  39. )BOETXJGU खࡳͷߏ଄ମ௥ՃͰΠϯελϯεΛฦ͢  private func insertCard(card: Card, atIndex index: Int)

    -> Hand { var mutableCards = cards mutableCards.insert(card, atIndex: index) return Hand(deck: deck, cards: mutableCards) }
  40. )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() } }
  41. )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) }
  42. )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) }
  43. ௥Ճ΍࡟আͱಉ༷ʹ Ҡಈ΋NVUBUJOHΛ֎͚͢Ͳ ͜͜ͰจԽΛௐ࿨ͤ͞Δ 

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

  45. )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) }
  46.  deleteCardAtIndex(fromIndex)ͷΠϯελϯε insertCard(cards[fromIndex], atIndex: toIndex)ͷΠϯελϯε cards[fromIndex] = ߏ଄ମͷϓϩύςΟ

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

  48. .PWFUPB$VTUPN$FMM

  49. .PEJpFE.77.  .PEFM7JFX7JFX.PEFM 

  50. $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 } }
  51. )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 }
  52. 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) // Ξϯϥοϓͨ͠ม਺Λ࢖͏͜ͱ͕Ͱ͖Δ }
  53. )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 }
  54. 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] }
  55. )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 }
  56. )BOE )BOE7$ .PEFM7JFX7JFX.PEFM  $BSE$FMM

  57. 4FDPOE%FNP 

  58. )BOE )BOE7$ .PEFM7JFX7JFX.PEFM  $BSE$FMM

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

  60. 5BLFUIF%BUB4PVSDFPVUPG UIF5BCMF7JFX$POUSPMMFS 

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

  62. %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) {} }
  63. )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) } }
  64. )BOE )BOE7$  %BUB4PVSDF

  65. %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) {} }
  66. – Daniel H Steinberg l͜ΕΒ͸ͪΐͬͱҧ͏ɻ Ҿ্͖͛Δɻ 1SPUPDPMΛ࢖͍·͢ɻz 

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

  68. )BOE )BOE7$  %BUB4PVSDF 4PVSDF5ZQF

  69. 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) } }
  70. %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) {} }
  71. QSPUPDPMFYUFOTJPOͱ͸ʁ w QSPUPDPMʢΠϯλϑΣʔεͷఆٛʣΛ֦ு͠ɺϝιουͷ࣮૷Λ௥Ճ͢Δػೳ w ศརͳQSPUPDPMFYUFOTJPO͕ͩɺ֨ೲܕϓϩύςΟΛ࣋ͭ͜ͱ͕Ͱ͖ͳ͍  protocol MyProtocol { func

    hoge() } extension MyProtocol { func hoge() { print("hoge") } } class MyClass: MyProtocol { } let myInstance = MyClass() myInstance.hoge() // hoge ͱग़ྗ͞ΕΔ
  72. )BOE )BOE7$  %BUB4PVSDF 4PVSDF5ZQF %BUB5ZQF

  73. )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 {} }
  74. )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 {} }
  75. %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 }
  76. %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 }
  77. – Daniel H Steinberg l)BOEΛฦ͍ͯͨ͠ͷΛ4FMGͰฦ͢Α͏ʹ͢Δɻ ʢ4FMG͸ʣ%BUB5ZQFʹ४ڌ͍ͯ͠Δऀࣗ਎ɻz 

  78. )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 {} }
  79. )BOE )BOE7$  %BUB4PVSDF 4PVSDF5ZQF %BUB5ZQF

  80. 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) } }
  81. %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) } } }
  82. %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 }
  83. 5IJSE%FNP 

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

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

  86. %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) } }
  87. – Daniel H Steinberg l͜Ε͸ʢ͜͜ʹʣ͋Δ΂͖Ͱ͠ΐ͏͔ʁz 

  88. 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) } }
  89. 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) } }
  90. %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) } }
  91. )BOE )BOE7$  )BOE%BUB4PVSDF 4PVSDF5ZQF %BUB5ZQF %BUB4PVSDF

  92. /PXQVTI)BOESFGFSFODF EPXOJOUPUIFTVCDMBTT

  93. )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 } }
  94. )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 } }
  95. %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 }
  96. %BUB4PVSDFTXJGU %BUB4PVSDFͷΠχγϟϥΠβ࡞੒  import UIKit class DataSource: NSObject, UITableViewDataSource, SourceType

    { var dataObject: DataType var conditionForAdding :Bool { return false } init<A: DataType>(dataObject: A) { self.dataObject = dataObject }
  97. )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) } }
  98. 'PSUI%FNP 

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

  100. )BOE )BOE7$  )BOE%BUB4PVSDF 4PVSDF5ZQF %BUB5ZQF %BUB4PVSDF

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

  102. )BOE )BOE7$  )BOE%BUB4PVSDF 4PVSDF5ZQF %BUB5ZQF %BUB4PVSDF

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

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

    τʹಋೖ͢ΔͱɺͲͷΑ͏ʹιʔε͕มԽ͢Δͷ͔ɺ ·ͩมԽͤ͟ΔΛಘͳ͍ͷ͔ɺUSZͯ͠Έ͍ͨɻ
  105. ͦΕͧΕͷ%FNP࣌఺ͷιʔε͸ɺ ԼهͷϦϙδτϦʹϒϥϯνΛ੾ͬ ͯอଘͨ͠ IUUQTHJUIVCDPNNBTBTIJTVUPV #MFOEJOH$VMUVSFT&YBNQMF

  106. ࢀߟࢿྉ 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 
  107. ࢀߟࢿྉ 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