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

Introduction Conv

Introduction Conv

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

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

hirose yudai

August 23, 2018
Tweet

More Decks by hirose yudai

Other Decks in Technology

Transcript

  1. ैདྷͷॻ͖ํ 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() } }
  2. ैདྷͷॻ͖ํ 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
  3. ैདྷͷॻ͖ํ 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
  4. ैདྷͷॻ͖ํ 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() } } ͲΕ͕ͲΕ
  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. 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) }) } } }
  7. 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) }) } } } ͜ΕͰ࡞Εͯ͠·͍·͢
  8. 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ΛҰ͚ͭͩఆٛͨ͠
  9. 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͕࡞ΒΕΔ
  10. 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ʹΞΫηε͠ͳ͍͍ͯ͘
  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) }) } } } 4FDUJPOʹ౉ͨ͠਺͚ͩ*UFN͕࡞ΒΕΔ
  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) }) } } } ഑ྻͷཁૉ͝ͱʹ*UFNΛఆٛ͢ΔͷͰ *OEFY1BUIʹΞΫηε͠ͳ͍͍ͯ͘
  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) }) } } } $FMM͝ͱͷ%BUB4PVSDFɾ%FMFHBUFͷϝιουͷϥούʔୡ
  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) }) } } } (FOFSJDTͰΩϟετ͞Εͨ$FMM͕౉ͬͯ͘Δ
  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ͱ*UFNͷؔ܎ੑ͕໌֬ʹɻݶఆతʹ
  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) }) } } } ແବͳGBUBM&SSPS͕ͳ͘ͳ͍ͬͯΔ