Introduction Conv

Introduction Conv

potatotips #54
https://potatotips.connpass.com/event/95391/

UICollectionViewを便利にかけるライブラリConvを作ったので紹介

C5fb6051a588c0b9dc308e97800098ad?s=128

hirose yudai

August 23, 2018
Tweet

Transcript

  1. QPUBUPUJQT 6*$PMMFDUJPO7JFXΛศརʹ͔͚ΔϥΠϒϥϦΛ࡞Γ·ͨ͠

  2. ࣗݾ঺հ *%CBOO[BJ ॴଐגࣜձࣾ"TPCJDB ৬ۀ&OHJOFFS ݺশελʔޤ৯ CBOO[BJ @CBOO[BJ@

  3. $POWͱ͍͏ϥΠϒϥϦΛ࡞Γ·ͨ͠ (JU)VCϦϙδτϦ IUUQTHJUIVCDPNCBOO[BJ$POW 2JJUBʹ΋ಉ͡λΠτϧͰهࣄΛॻ͍ͨ IUUQTRJJUBDPNCBOO[BJJUFNTGECFDDBECF

  4. Ͳ͏ศརͳͷʁ

  5. ैདྷͷॻ͖ํ public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) ->

    Int { switch section { case 0: return users.count case 1: return hobbies.count case 2: return teams.count default: fatalError() } } public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { switch (indexPath.section, indexPath.item) { case (0, _): let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ACell", for: indexPath) as! UserCell cell.configure(with: users[indexPath.item]) ... return cell case (1, _): let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "BCell", for: indexPath) as! HobbyCell cell.configure(with: hobbies[indexPath.item]) ... return cell case (2, _): let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CCell", for: indexPath) as! TeamCell cell.configure(with: teams[indexPath.item]) ... return cell default: fatalError() } }
  6. ैདྷͷॻ͖ํ public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) ->

    Int { switch section { case 0: return users.count case 1: return hobbies.count case 2: return teams.count default: fatalError() } } public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { switch (indexPath.section, indexPath.item) { case (0, _): let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ACell", for: indexPath) as! UserCell cell.configure(with: users[indexPath.item]) ... return cell case (1, _): let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "BCell", for: indexPath) as! HobbyCell cell.configure(with: hobbies[indexPath.item]) ... return cell case (2, _): let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CCell", for: indexPath) as! TeamCell cell.configure(with: teams[indexPath.item]) ... return cell default: fatalError() } } ύλʔϯϚον͠ͳ͍৔߹ͷGBUBM&SSPS
  7. ैདྷͷॻ͖ํ public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) ->

    Int { switch section { case 0: return users.count case 1: return hobbies.count case 2: return teams.count default: fatalError() } } public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { switch (indexPath.section, indexPath.item) { case (0, _): let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ACell", for: indexPath) as! UserCell cell.configure(with: users[indexPath.item]) ... return cell case (1, _): let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "BCell", for: indexPath) as! HobbyCell cell.configure(with: hobbies[indexPath.item]) ... return cell case (2, _): let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CCell", for: indexPath) as! TeamCell cell.configure(with: teams[indexPath.item]) ... return cell default: fatalError() } } ࢄΒ͹Δ'PSDFVOXSBQ
  8. ैདྷͷॻ͖ํ public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) ->

    Int { switch section { case 0: return users.count case 1: return hobbies.count case 2: return teams.count default: fatalError() } } public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { switch (indexPath.section, indexPath.item) { case (0, _): let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ACell", for: indexPath) as! UserCell cell.configure(with: users[indexPath.item]) ... return cell case (1, _): let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "BCell", for: indexPath) as! HobbyCell cell.configure(with: hobbies[indexPath.item]) ... return cell case (2, _): let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CCell", for: indexPath) as! TeamCell cell.configure(with: teams[indexPath.item]) ... return cell default: fatalError() } } ͲΕ͕ͲΕ
  9. ैདྷͷॻ͖ํ public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) ->

    Int { switch section { case 0: return users.count case 1: return hobbies.count case 2: return teams.count default: fatalError() } } public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { switch (indexPath.section, indexPath.item) { case (0, _): let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ACell", for: indexPath) as! UserCell cell.configure(with: users[indexPath.item]) ... return cell case (1, _): let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "BCell", for: indexPath) as! HobbyCell cell.configure(with: hobbies[indexPath.item]) ... return cell case (2, _): let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CCell", for: indexPath) as! TeamCell cell.configure(with: teams[indexPath.item]) ... return cell default: fatalError() } } ཁૉͷؔ܎ੑ͕ബ͍ɾԕ͍
  10. $POWΛ࢖͏ͱ

  11. collectionView .conv() .create(for: SectionType.allCases) { (sectionType, section) in // ※2

    switch sectionType { case .users: section.create(for: users) { user, item: Item<UserCell> in item.reusableIdentifier = "ACell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: user) }) } case .hobbies: section.create(for: hobbies) { hobby, item: Item<ItemCell> in item.reusableIdentifier = "BCell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: hobby) }) } case .teams: section.create(for: teams) { team, item: Item<ItemCell> in item.reusableIdentifier = "CCell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: team) }) } } }
  12. collectionView .conv() .create(for: SectionType.allCases) { (sectionType, section) in // ※2

    switch sectionType { case .users: section.create(for: users) { user, item: Item<UserCell> in item.reusableIdentifier = "ACell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: user) }) } case .hobbies: section.create(for: hobbies) { hobby, item: Item<ItemCell> in item.reusableIdentifier = "BCell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: hobby) }) } case .teams: section.create(for: teams) { team, item: Item<ItemCell> in item.reusableIdentifier = "CCell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: team) }) } } } ͜ΕͰ࡞Εͯ͠·͍·͢
  13. collectionView .conv() .create(for: SectionType.allCases) { (sectionType, section) in // ※2

    switch sectionType { case .users: section.create(for: users) { user, item: Item<UserCell> in item.reusableIdentifier = "ACell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: user) }) } case .hobbies: section.create(for: hobbies) { hobby, item: Item<ItemCell> in item.reusableIdentifier = "BCell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: hobby) }) } case .teams: section.create(for: teams) { team, item: Item<ItemCell> in item.reusableIdentifier = "CCell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: team) }) } } } ͚ͩ͜͜&OVNΛҰ͚ͭͩఆٛͨ͠
  14. collectionView .conv() .create(for: SectionType.allCases) { (sectionType, section) in // ※2

    switch sectionType { case .users: section.create(for: users) { user, item: Item<UserCell> in item.reusableIdentifier = "ACell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: user) }) } case .hobbies: section.create(for: hobbies) { hobby, item: Item<ItemCell> in item.reusableIdentifier = "BCell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: hobby) }) } case .teams: section.create(for: teams) { team, item: Item<ItemCell> in item.reusableIdentifier = "CCell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: team) }) } } } ഑ྻΛ౉ͨ͠਺͚ͩ4FDUJPO͕࡞ΒΕΔ
  15. collectionView .conv() .create(for: SectionType.allCases) { (sectionType, section) in // ※2

    switch sectionType { case .users: section.create(for: users) { user, item: Item<UserCell> in item.reusableIdentifier = "ACell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: user) }) } case .hobbies: section.create(for: hobbies) { hobby, item: Item<ItemCell> in item.reusableIdentifier = "BCell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: hobby) }) } case .teams: section.create(for: teams) { team, item: Item<ItemCell> in item.reusableIdentifier = "CCell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: team) }) } } } ഑ྻͷཁૉ͝ͱʹ4FDUJPOΛఆٛ͢ΔͷͰ *OEFY1BUIʹΞΫηε͠ͳ͍͍ͯ͘
  16. collectionView .conv() .create(for: SectionType.allCases) { (sectionType, section) in // ※2

    switch sectionType { case .users: section.create(for: users) { user, item: Item<UserCell> in item.reusableIdentifier = "ACell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: user) }) } case .hobbies: section.create(for: hobbies) { hobby, item: Item<ItemCell> in item.reusableIdentifier = "BCell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: hobby) }) } case .teams: section.create(for: teams) { team, item: Item<ItemCell> in item.reusableIdentifier = "CCell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: team) }) } } } 4FDUJPOʹ౉ͨ͠਺͚ͩ*UFN͕࡞ΒΕΔ
  17. collectionView .conv() .create(for: SectionType.allCases) { (sectionType, section) in // ※2

    switch sectionType { case .users: section.create(for: users) { user, item: Item<UserCell> in item.reusableIdentifier = "ACell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: user) }) } case .hobbies: section.create(for: hobbies) { hobby, item: Item<ItemCell> in item.reusableIdentifier = "BCell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: hobby) }) } case .teams: section.create(for: teams) { team, item: Item<ItemCell> in item.reusableIdentifier = "CCell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: team) }) } } } ഑ྻͷཁૉ͝ͱʹ*UFNΛఆٛ͢ΔͷͰ *OEFY1BUIʹΞΫηε͠ͳ͍͍ͯ͘
  18. collectionView .conv() .create(for: SectionType.allCases) { (sectionType, section) in // ※2

    switch sectionType { case .users: section.create(for: users) { user, item: Item<UserCell> in item.reusableIdentifier = "ACell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: user) }) } case .hobbies: section.create(for: hobbies) { hobby, item: Item<ItemCell> in item.reusableIdentifier = "BCell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: hobby) }) } case .teams: section.create(for: teams) { team, item: Item<ItemCell> in item.reusableIdentifier = "CCell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: team) }) } } } $FMM͝ͱͷ%BUB4PVSDFɾ%FMFHBUFͷϝιουͷϥούʔୡ
  19. collectionView .conv() .create(for: SectionType.allCases) { (sectionType, section) in // ※2

    switch sectionType { case .users: section.create(for: users) { user, item: Item<UserCell> in item.reusableIdentifier = "ACell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: user) }) } case .hobbies: section.create(for: hobbies) { hobby, item: Item<ItemCell> in item.reusableIdentifier = "BCell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: hobby) }) } case .teams: section.create(for: teams) { team, item: Item<ItemCell> in item.reusableIdentifier = "CCell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: team) }) } } } (FOFSJDTͰΩϟετ͞Εͨ$FMM͕౉ͬͯ͘Δ
  20. collectionView .conv() .create(for: SectionType.allCases) { (sectionType, section) in // ※2

    switch sectionType { case .users: section.create(for: users) { user, item: Item<UserCell> in item.reusableIdentifier = "ACell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: user) }) } case .hobbies: section.create(for: hobbies) { hobby, item: Item<ItemCell> in item.reusableIdentifier = "BCell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: hobby) }) } case .teams: section.create(for: teams) { team, item: Item<ItemCell> in item.reusableIdentifier = "CCell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: team) }) } } } 4FDUJPOͱ*UFNͷؔ܎ੑ͕໌֬ʹɻݶఆతʹ
  21. collectionView .conv() .create(for: SectionType.allCases) { (sectionType, section) in // ※2

    switch sectionType { case .users: section.create(for: users) { user, item: Item<UserCell> in item.reusableIdentifier = "ACell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: user) }) } case .hobbies: section.create(for: hobbies) { hobby, item: Item<ItemCell> in item.reusableIdentifier = "BCell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: hobby) }) } case .teams: section.create(for: teams) { team, item: Item<ItemCell> in item.reusableIdentifier = "CCell" item.size = ... item.configureCell({ cell, _ in cell.configure(with: team) }) } } } ແବͳGBUBM&SSPS͕ͳ͘ͳ͍ͬͯΔ
  22. ͍͍͡ΌΜ

  23. ͍͍͘͢͝

  24. ࠷ߴ

  25. ͓·͚ $POWͰ͸ࠩ෼ߋ৽ͷΞϧΰϦζϜͱͯ͠ 1BVM)FDLFMTBMHPSJUINΛϕʔεͱͯ͠࡞͍ͬͯ ·͢ɻͳͷͰඞཁͳ෦෼͚ͩߋ৽͢ΔͷͰແବͳॲཧ ͕ͳ͍ *(-JTU,JU͕ಉ͡ΞϧΰϦζϜ࢖͍ͬͯΔ IUUQTHJUIVCDPN*OTUBHSBN*(-JTU,JU

  26. ͓ΘΓʹ (JU)VCϦϙδτϦ IUUQTHJUIVCDPNCBOO[BJ$POW 2JJUBʹ΋ಉ͡λΠτϧͰهࣄΛॻ͍ͨ IUUQTRJJUBDPNCBOO[BJJUFNTGECFDDBECF

  27. ͓͠·͍a ?P?