Speaker Deck
Speaker Deck Pro
Sign in
Sign up
for free
Introduction Conv
hirose yudai
August 23, 2018
Technology
3
790
Introduction Conv
potatotips #54
https://potatotips.connpass.com/event/95391/
UICollectionViewを便利にかけるライブラリConvを作ったので紹介
hirose yudai
August 23, 2018
Tweet
Share
More Decks by hirose yudai
See All by hirose yudai
bannzai
0
7
bannzai
0
180
bannzai
0
570
bannzai
0
15
bannzai
0
61
bannzai
4
290
bannzai
6
1.6k
bannzai
0
280
bannzai
0
46
Other Decks in Technology
See All in Technology
110y
3
690
clustervr
0
210
yukitodate
2
310
minamizaki
0
510
kawaguti
0
110
mmarukaw
0
1.4k
line_developers
PRO
0
780
takem001
0
840
con_mame
4
2k
kaga
0
190
satotakeshi
2
400
kanaugust
PRO
0
210
Featured
See All Featured
reverentgeek
27
1.9k
tenderlove
52
3.4k
cassininazir
347
20k
eileencodes
113
25k
sugarenia
233
830k
chriscoyier
145
19k
jensimmons
207
10k
danielanewman
1
470
malarkey
192
8.5k
pauljervisheath
196
15k
jnunemaker
PRO
40
4.5k
roundedbygravity
241
21k
Transcript
QPUBUPUJQT 6*$PMMFDUJPO7JFXΛศརʹ͔͚ΔϥΠϒϥϦΛ࡞Γ·ͨ͠
ࣗݾհ *%CBOO[BJ ॴଐגࣜձࣾ"TPCJDB ৬ۀ&OHJOFFS ݺশελʔޤ৯ CBOO[BJ @CBOO[BJ@
$POWͱ͍͏ϥΠϒϥϦΛ࡞Γ·ͨ͠ (JU)VCϦϙδτϦ IUUQTHJUIVCDPNCBOO[BJ$POW 2JJUBʹಉ͡λΠτϧͰهࣄΛॻ͍ͨ IUUQTRJJUBDPNCBOO[BJJUFNTGECFDDBECF
Ͳ͏ศརͳͷʁ
ैདྷͷॻ͖ํ 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() } }
ैདྷͷॻ͖ํ 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
ैདྷͷॻ͖ํ 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
ैདྷͷॻ͖ํ 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() } } ͲΕ͕ͲΕ
ैདྷͷॻ͖ํ 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() } } ཁૉͷؔੑ͕ബ͍ɾԕ͍
$POWΛ͏ͱ
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) }) } } }
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) }) } } } ͜ΕͰ࡞Εͯ͠·͍·͢
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ΛҰ͚ͭͩఆٛͨ͠
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͕࡞ΒΕΔ
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ʹΞΫηε͠ͳ͍͍ͯ͘
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͕࡞ΒΕΔ
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ʹΞΫηε͠ͳ͍͍ͯ͘
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ͷϝιουͷϥούʔୡ
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͕ͬͯ͘Δ
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ͷؔੑ͕໌֬ʹɻݶఆతʹ
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͕ͳ͘ͳ͍ͬͯΔ
͍͍͡ΌΜ
͍͍͘͢͝
࠷ߴ
͓·͚ $POWͰࠩߋ৽ͷΞϧΰϦζϜͱͯ͠ 1BVM)FDLFMTBMHPSJUINΛϕʔεͱͯ͠࡞͍ͬͯ ·͢ɻͳͷͰඞཁͳ෦͚ͩߋ৽͢ΔͷͰແବͳॲཧ ͕ͳ͍ *(-JTU,JU͕ಉ͡ΞϧΰϦζϜ͍ͬͯΔ IUUQTHJUIVCDPN*OTUBHSBN*(-JTU,JU
͓ΘΓʹ (JU)VCϦϙδτϦ IUUQTHJUIVCDPNCBOO[BJ$POW 2JJUBʹಉ͡λΠτϧͰهࣄΛॻ͍ͨ IUUQTRJJUBDPNCBOO[BJJUFNTGECFDDBECF
͓͠·͍a ?P?