๊ณต๋ถ€ ์—ฐ์Šต์žฅ :-)

TIL_20180820 ~ 20180825

|

2018.08.20

  • ๋„ค๋น„๊ฒŒ์ด์…˜ bar์— ๊ฐ€๋ ค์ง€๋Š” frame ์ˆ˜์ •
  • ์ฝ”๋“œ๋กœ safeArea์˜์—ญ ์•Œ์•„๋‚ด๋Š”๋ฒ• ์„œ์นญ

2018.08.22

  • ํ‘ธ์‹œ์— ๋Œ€ํ•ด์„œ ๊ณต๋ถ€!
  • ๊ผผ๊ผผํ•œ ์žฌ์€์”จ - ๋กœ์ปฌํ‘ธ์‹œ๋ถ€ํ„ฐ ๋จผ์ € ใ…Ž_ใ…Ž

์งˆ๋ฌธํˆฌ์„ฑ์ด

์•Œ๋ฆฐ [8:08 PM]
์—ฌ๋Ÿฌ๋ถ„ใ… ใ…  ๋งŒ์•ฝ ๋ฃจํŠธ๋ทฐ์ปจํŠธ๋กค๋Ÿฌ๊ฐ€ ์‹ฑ๊ธ€ํ†ค ํ”„๋กœํผํ‹ฐ๋ฅผ ๊ฐ€์ง€๊ณ ์žˆ์œผ๋ฉด AppDelegate์˜ `application()`ํ•จ์ˆ˜๊ฐ€ ์‹คํ–‰๋˜๊ธฐ๋„ ์ „์— ๋จผ์ € ๋ฃจํŠธ๋ทฐ์ปจํŠธ๋กค๋Ÿฌ์˜ ํ”„๋กœํผํ‹ฐ๊ฐ€ ์ดˆ๊ธฐํ™”๋˜๋Š”๊ฑด๊ฐ€์š”โ€ฆ?
class MainViewController: UIViewController {
    let favorites = FavoriteList.shared().martList
    ...
}

์‹ฑ๊ธ€ํ†ค ํ”„๋กœํผํ‹ฐ๋Š” ์ €๋ ‡๊ฒŒ ๊ฐ€์ง€๊ณ ์žˆ๊ณ ์š”, ๋™์ž‘์„ ์ด์ƒํ•˜๊ฒŒ ํ•˜๊ธธ๋ž˜ ๋ธŒ๋ ˆ์ดํฌํฌ์ธํŠธ๋ฅผ ๊ฑธ์–ด๋ดค๋”๋‹ˆ ๋จผ์ € ์ € ์ฝ”๋“œ์˜  `let favorites = FavoriteList.shared().martList` ์ด๊ฒŒ ๋จผ์ € ์‹คํ–‰๋˜๊ณ  ๊ทธ ๋‹ค์Œ์— `application()`ํ•จ์ˆ˜๋ฅผ ํƒ€๋„ค์š”! ๋ญ”๊ฐ€ ์ด์ƒํ•œ๊ฑด์ง€ ํ™•์‹ ํ• ์ˆ˜๊ฐ€ ์—†์–ด์„œ ์งˆ๋ฌธํ•ฉ๋‹ˆ๋‹น!โ€ฆ?_?

๋ƒ…์Šคํ„ฐ [8:18 PM]
๋ทฐ๋””๋“œ๋กœ๋“œํ• ๋•Œ ์ดˆ๊ธฐํ™”ํ•˜๋ฉด ์–ด๋–จ๊นŒ์š”

Mason [8:36 PM]
static์€ ํ•ญ์ƒ ๋จผ์ € ํ• ๋‹น๋˜๋Š”๊ฑธ๋กœ ์•Œ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค
ํด๋ž˜์Šค๋‚˜ ๊ตฌ์กฐ์ฒด์•ˆ์— static์œผ๋กœ ์„ ์–ธ๋œ ํ”„๋กœํผํ‹ฐ๊ฐ€ ์žˆ์„๊ฒฝ์šฐ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜์ง€ ์•Š์•„๋„ ~์ ‘๊ทผํ• ์ˆ˜ ์žˆ๋Š”์ด์œ ๋กœ ์•Œ๊ณ  ์žˆ์–ด์š”~ static์€ ๊ธ€๋กœ๋ฒŒ ์˜์—ญ์ด๋ผ์„œ(๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ์ œ์ด์ผ€์ด) (edited)
shared()๋„ ํƒ€์ž…๋ฉ”์„œ๋“œ๋ผ๋ฉด static์ฒ˜๋Ÿผ ๋จผ์ € ๋ฉ”๋ชจํžˆ์— ์˜ฌ๋ผ๊ฐ€์„œ ๊ทธ๋Ÿฌ์ง€ ์•Š์„๊นŒ์š”
๋งŒ์•ฝ์— FavoriteList๊ฐ€ ์‹ฑ๊ธ€ํ†ค ๊ฐ์ฒด๋ผ๋ฉด ๊ตณ์ด ํ”„๋กœํผํ‹ฐ๋กœ ๊ฐ–๊ณ  ์žˆ์„ ํ•„์š”๊ฐ€ ์—†์–ด๋„๋ ๊ฑฐ๊ฐ™์•„์š”

์•Œ๋ฆฐ [8:39 PM]
๋„ค๋„ค ์‚ฌ์‹ค ์ €๊ฑด ๋˜๋Š”์ง€ํ™•์ธ์„ ์œ„ํ•ด์„œ ๊ธ‰ํ•˜๊ฒŒ ์ง  ์ฝ”๋“œ๋ผโ€ฆใ…‹ใ…‹ใ…‹ ๊ทธ๋ž˜์„œ ์ง€๊ธˆ์€ ๋ฃจํŠธ๋ทฐ์ปจํŠธ๋กค๋Ÿฌ์˜ ํ”„๋กœํผํ‹ฐ๋ฅผ ์•ฑ๋ธ๋ฆฌ๊ฒŒ์ดํŠธ์—์„œ ํ• ๋‹นํ•ด์ฃผ๋Š”๊ฑธ๋กœ ๋ฐ”๊ฟจ์–ด์š”
static์ด๋ผ์„œ ๋จผ์ € ๋ธŒ๋ ˆ์ดํฌํฌ์ธํŠธ์— ๊ฑธ๋ฆฌ๋Š”๊ฑฐ์˜€๊ตฐ์š” ์ €๋Š” applicationํ•จ์ˆ˜๋ณด๋‹ค ๋‹ค๋ฅธ๊ฒŒ ๋จผ์ € ์‹คํ–‰๋˜๋Š” ๊ฒฝ์šฐ๋ฅผ ์ง€๊ธˆ ์ฒ˜์Œ ๋ด์„œใ… ใ… ใ… ๋ชฐ๋ž๋„ค์š” ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค

Mason [8:49 PM]
ํƒ€์ž…ํ”„๋กœํผํ‹ฐ๋Š” ์ผ๋ฐ˜ ํ”„๋กœํผํ‹ฐ๋ž‘ ์ดˆ๊ธฐํ™” ์‹œ์ ์ด ์•„์˜ˆ ๋‹ฌ๋ผ์„œ ๊ทธ๋Ÿด๊ฑฐ์—์š” static์€ ํ•ญ์ƒ ๊ธฐ๋ณธ๊ฐ’์ด ์žˆ์–ด์•ผ๋˜๋Š” ์ด์œ ๋กœ ์•Œ๊ณ  ์žˆ์–ด์š”
@JK ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰์‹œ ๋ฉ”๋ชจ๋ฆฌ ํ• ๋‹น์€ ์Šคํƒ์ด ๋จผ์ € ํ• ๋‹น์ด๋˜๋‚˜์š”?

JK [8:52 PM]
์Šคํƒ์€ ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœ๋ ๋•Œ๋งˆ๋‹ค ์ž…๋‹ˆ๋‹ค. ๋จผ์ €๋ผ๋Š”๊ฑด ์ƒ๋Œ€์ ์ธ ์‹œ๊ฐ„์ฐจ์ด์ผ ๋ฟ์ด์ฃ .

JK [8:58 PM]
์ฐธ๊ณ ๋กœ static์€ ๊ธ€๋กœ๋ฒŒ ๋ณ€์ˆ˜ ๊ฐœ๋…์ด๋ผ ๋กœ๋”ฉ์‹œ์ ์— ๋จผ์ € ์ƒ์„ฑ๋˜๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค.

Mason [8:58 PM]
class์™€ struct์ƒ๊ด€์—†๋‚˜์š”?
ํด๋ž˜์Šคํƒ€๋‹™์•ˆ์— ์„ ์–ธ๋œ static๋„ ํž™์ด ์•„๋‹Œ ์Šคํƒ ๊ณต๊ฐ„์— ์˜ฌ๋ผ๊ฐ€๋‚˜์š”?(๋ณ„๋กœ ์ค‘์š”ํ•œ๊ฑด ์•„๋‹™๋‹ˆ๋‹ค...) (edited)

JK [9:08 PM]
์œ„์— static ์–˜๊ธฐํ•œ ๊ธ€๋กœ๋ฒŒ์€ ์Šคํƒ. ํž™๊ณผ ๋ณ„๊ฐœ์ธ ๊ธ€๋กœ๋ฒŒ ์˜์—ญ์ž…๋‹ˆ๋‹ค.

JK [9:14 PM]
@์•Œ๋ฆฐ rootVC๊ฐ€ AppDelegate.window ์— ๋“ค์–ด๊ฐ€๋Š” ์ธ์Šคํ„ด์Šค๋ผ์„œ ์ดˆ๊ธฐํ™” ์‹œ์ ์— ๋งŒ๋“ค์–ด์ง‘๋‹ˆ๋‹ค. ๊ทธ๋•Œ ๊ฐ™์ด ๋ฉ”๋ชจ๋ฆฌ์— ํ• ๋‹น๋˜๋Š”๊ฑฐ์ฃ .
๊ทธ๋ฆฌ๊ณ ๋‚˜์„œ ๋ฉ”๋ชจ๋ฆฌ ์ž‘์—…์ด ๋๋‚˜๋ฉด ์ฝœ๋ฐฑ์ด ํ˜ธ์ถœ๋˜๊ณ !!

Mason [9:17 PM]
๋˜ ๋ฐฐ์›Œ๊ฐ‘๋‹ˆ๋‹ค

๋ƒ…์Šคํ„ฐ [10:09 PM]
์™€์šฐ

์•Œ๋ฆฐ [2:05 PM]
@JK ์–ด์ œ ๋‹ต๋ณ€์ฃผ์‹ ๊ฑฐ์—๋Œ€ํ•ด์„œ ๊ถ๊ธˆํ•œ๊ฒŒ ์žˆ๋Š”๋ฐ์š”ใ…‹_ใ…‹ ์–ด์ œ ๋˜ ๋” ํ•˜๋‹ค๋ณด๋‹ˆ๊นŒ
์ง€๊ธˆ ์ œ ์•ฑ์˜ ๋ชจ๋“  ๋ทฐ์ปจ์ด ๋„ค๋น„๊ฒŒ์ด์…˜์ปจํŠธ๋กค๋Ÿฌ์— embed๋˜์–ด์žˆ์–ด์„œ,
์•ฑ๋ธ๋ฆฌ๊ฒŒ์ดํŠธ์—์„œ  `let rootVC = self.window?.rootViewController` ์ด๋ ‡๊ฒŒ ์ ‘๊ทผํ•œ ๋ฃจํŠธ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ๋Š” MainViewController๊ฐ€ ์•„๋‹ˆ๋ผ UINavigationControllerํƒ€์ž…์ด๋”๋ผ๊ณ ์š”
๊ทผ๋ฐ ์–ด์ œ์˜ let favorites ๋ณ€์ˆ˜๋Š” MainViewController์˜ ํ”„๋กœํผํ‹ฐ์˜€๋Š”๋ฐ, ๊ทธ๋Ÿฌ๋ฉด ์–ด์ œ ๋ง์”€ํ•˜์‹  ์ดˆ๊ธฐํ™”์‹œ์ ์—์„œ๋Š” ๋ฃจํŠธ๋ทฐ์ธ UINavigationController๋ฟ๋งŒ์ด ์•„๋‹ˆ๋ผ ์™œ MainViewController๊นŒ์ง€ ๋ฉ”๋ชจ๋ฆฌ์— ํ• ๋‹น๋˜๋Š”๊ฑด๊ฐ€์š”?_?

์ œ ์ถ”์ธก์—” entry point๊ฐ€ ์•„๋ฌด๋ฆฌ ๋„ค๋น„๊ฒŒ์ด์…˜ ์ปจํŠธ๋กค๋Ÿฌ์—ฌ๋„ ์ฒซ ํ™”๋ฉด์—” MainViewController๊นŒ์ง€ ๋ณด์ด๋‹ˆ๊นŒ window๊ฐ€ ์ฒ˜์Œ์— ๋ณด์ด๋Š” ๋ชจ๋“  ํ™”๋ฉด์„ ๋‹ค ์ดˆ๊ธฐํ™”ํ•˜๋ ค๊ณ ํ•ด์„œ ๊ทธ๋Ÿฐ๊ฑฐ๊ฐ™๋‹ค๊ณ  ์ƒ๊ฐ์€ ํ•˜๋Š”๋ฐ..๊ถ๊ธˆํ•ด์„œ์š”!

๋ƒ…์Šคํ„ฐ [2:06 PM]
๋ฉ”์ธ๋ทฐ๊ฐ€์žˆ์–ด์•ผ ๋„ค๋น„๊ฒŒ์ด์…˜์ปจํŠธ๋กค๋Ÿฌ๋„ ์žˆ์–ด์„œ ๊ทธ๋Ÿฐ๊ฑฐ์•„๋‹๊นŒ์š” ๋ผ๋Š” ์ถ”์ธก์„ ๋‚จ๊ธฐ๊ณ  ์‚ฌ๋ผ์ง‘๋‹ˆ๋‹ค..

์•Œ๋ฆฐ [2:07 PM]
์•ˆ๋ผโ€ฆ

jake [2:07 PM]
๋นŒ๋“œ ์‹œ์ ์—์„œ ๋ชจ๋“  ํด๋ž˜์Šค๋ž‘ ์ŠคํŠธ๋ŸญํŠธ๋ฅผ ๊ฒ€์‚ฌํ• ๊ฑฐ์—์š”
๊ทธ๋Ÿฌ๋ฉด์„œ ํž™๋ฉ”๋ชจ๋ฆฌ๋‚˜ ์Šคํƒ์— ์Œ“์„๊ฒƒ๋“ค์ด ๊ตฌ๋ถ„๋˜์–ด์„œ ์ €์žฅํ•˜๊ณ  ์žˆ๋Š”๋ฐ
๊ทธ ๊ณผ์ •์—์„œ static๋ณ€์ˆ˜๊ฐ€ ๋”ฐ๋กœ ๊ด€๋ฆฌ๋˜๋Š”๊ฑฐ์ฃ 
๊ทธ๋Ÿฐ ๊ฒƒ๋“ค์ด ์ •์˜ ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋‚˜์ค‘์— ๋ฐ”๋กœ ์ฐธ์กฐํ•ด์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š”๊ฑธ๋กœ ์•Œ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค

์•Œ๋ฆฐ [2:13 PM]
์•„ํ•˜ ๊ทธ๋Ÿผ `let favorites`๋ณ€์ˆ˜๊ฐ€ ๊ทธ๋ƒฅ ์ผ๋ฐ˜์ ์ธ ๋กœ์ปฌ๋ณ€์ˆ˜์˜€๋‹ค๋ฉด ์–ด์ œ์ฒ˜๋Ÿผ ๋™์ž‘ํ•˜์ง€ ์•Š์•˜์„ ์ˆ˜ ์žˆ๊ฒ ๋„ค์š”..? Favorites.shared()๋ผ๋Š” static์— ์ ‘๊ทผํ•ด์„œ ๊ทธ๋ ‡๊ฒŒ ๋™์ž‘ํ•œ๊ฑด๊ฐ€..

jake [2:15 PM]
main๋ง๊ณ  ๋‹ค๋ฅธ๋ฐ๋„ ์ฐ์–ด๋ณด์…จ๋‚˜์š”? ๋กœ๋ฒŒ ๋ณ€์ˆ˜์—๋„ ์ฐ์–ด๋ณด์„ธ์š”
ํด๋ž˜์Šค๊ฐ€ ๋งŒ๋“ค์–ด์งˆ๋•Œ ์ „๋ถ€ ์ ‘๊ทผํ•˜๊ณ 
๋งŒ๋“ค์–ด์ง„ ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  application์ด ๋™์ž‘ํ•˜๋Š”๊ฒŒ ์•„๋‹๊ฐ€ ์‹ถ๋„ค์š”

Mason [2:21 PM]
์ฐพ์•˜๋‹ค..์˜ˆ์ „์— ๋ถ„๋ช…ํžˆ ์ œ์ด์ผ€์ด๊ฐ€ ๊ฐ•์˜๋•Œ ๋ณด์—ฌ์ฃผ์…จ์—ˆ๋Š”๋ฐโ€ฆ๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด ์Šฌ๋ผ์ด๋“œ์— ์žˆ์—ˆ๋„ค์š”!
Pasted image at 2018-08-22, 2:21 PM

GVAR์ €๊ธฐ๊ฐ€ ์–ด์ œ ๋ง์”€ํ•ด์ฃผ์‹  ๊ธ€๋กœ๋ฒŒ์˜์—ญ์ธ๋“ฏํ•ฉ๋‹ˆ๋‹ค
static๋ณ€์ˆ˜๋Š” ์ € ์˜์—ญ์— ์ €์žฅ๋˜๋Š”๊ฑฐ๊ฒ ์ฃ 
(์•„ ์ด๊ฑด ์œ—๋ถ„๋“ค ์งˆ๋ฌธ๊ณผ ๋ณ„๊ฐœ๋กœโ€ฆ ๊ณต์œ โ€ฆ) (edited)

2018.08.23

  • ๋ถ€์ŠคํŠธ์ฝ”์Šค ํŠน๊ฐ•์„ ๋‹ค๋…€์˜ด. ์‹ ์ž… ๊ฐœ๋ฐœ์ž๋กœ ์ทจ์—…ํ•ด์•ผํ• ๋•Œ ์ฑ™๊ฒจ์•ผ ํ•  ๊ฒƒ๋“ค์„ ์•Œ ์ˆ˜ ์žˆ์—ˆ๋‹ค.

2018.08.25

  • ์ฃผ๋ง์„ ํ™”๋ คํ•˜๊ฒŒ ์žฅ์‹ํ•œ ์ฝœ๋ ‰์…˜๋ทฐ ์…€์— ์ฝœ๋ ‰์…˜๋ทฐ ๋„ฃ๊ธฐ ์‚ฝ์งˆ..

  • FavoriteCollectionView์˜ cell ๋‚ด๋ถ€์— ๋˜ ๋‹ค๋ฅธ ์ฝœ๋ ‰์…˜๋ทฐ๋ฅผ ๋„ฃ์–ด์•ผํ•˜๋Š” ์ƒํ™ฉ(holidaysCollectionView)
  • holidaysCollectionView๋˜ํ•œ ๋ฉ”์ธ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ์—์„œ ์—ฐ๊ฒฐํ•˜๊ณ  delegate์™€ dataSource๋ฅผ ๋‹ด๋‹นํ•˜๋ คํ–ˆ์œผ๋‚˜ ๋ฐ˜๋ณต๋˜๋Š” ์š”์†Œ๋Š” outlet์œผ๋กœ ์—ฐ๊ฒฐํ• ์ˆ˜ ์—†๋‹ค๋Š” ์—๋Ÿฌ ๋ฐœ์ƒ
  • FavoriteCollectionView์˜ ์…€์ด ์žฌ์‚ฌ์šฉ๋˜๋ฉด์„œ ๋‚ด๋ถ€์˜ holidaysCollectionView๊ฐ€ ์—ฌ๋Ÿฌ๊ฐœ ์ƒ๊ธฐ๊ธฐ๋•Œ๋ฌธ
  • ๋”ฐ๋ผ์„œ holidaysCollectionView์˜ delegate์™€ dataSource๋Š” MainViewController๊ฐ€ ๋‹ด๋‹นํ•  ์ˆ˜ ์—†๊ณ  FavoriteCollectionView์˜ ์…€(favoriteCell)์ด ๋‹ด๋‹นํ•ด์•ผ ํ•˜๋Š” ์ƒํ™ฉ
  • ํ•˜์ง€๋งŒ favoriteCell์€ ๋ทฐ์ž„โ€ฆ
  • holidaysCollectionView์˜ delegate์™€ dataSource๋ฅผ ๋‹ด๋‹นํ•  ๋‹ค๋ฅธ ๋ชจ๋ธ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค๊ณ  favoriteCell๋‚ด๋ถ€์—์„œ ์ž์‹  ๋‚ด๋ถ€์—์žˆ๋Š” ์ฝœ๋ ‰์…˜๋ทฐ์˜ ๋ธ๋ฆฌ๊ฒŒ์ดํŠธ์™€ ๋ฐ์ดํ„ฐ์†Œ์Šค๋ฅผ ๋ถ€์—ฌํ•˜๋Š” ํ๋ฆ„์œผ๋กœ ๊ฐ€๊ธฐ๋กœ ๊ฒฐ์ •..!
  • ์ฐธ๊ณ ๋งํฌ-stackoverflow
  • โ€ฆ.ํ•˜์ง€๋งŒ ๋‚ ์งœ์ฝœ๋ ‰์…˜๋ทฐ๊ฐ€ ํ‘œ์‹œ๋˜์ง€์•Š์Œ!
  • ์œ„์—์„œ ํ๋ฆ„์„ ์ €๋ ‡๊ฒŒ ์ง€์ •ํ•˜๊ณ , ์•„๋ž˜์™€ ๊ฐ™์ด ์‹คํ–‰ํ–ˆ๋‹ค. ํ•˜์ง€๋งŒ ์ฝœ๋ ‰์…˜๋ทฐ์…€ ๋‚ด๋ถ€์˜ ์ฝœ๋ ‰์…˜๋ทฐ๊ฐ€ ํ‘œ์‹œ๋˜์ง€์•Š๋Š”๋‹ค..
  • FavoriteCellํด๋ž˜์Šค๋Š” ๋ทฐ์ด๊ธฐ๋•Œ๋ฌธ์— ์…€ ๋‚ด๋ถ€์— ๋“ค์–ด๊ฐ€๋Š” ์ฝœ๋ ‰์…˜ ๋ทฐ(holidaysCollectionView)์˜ ๋ธ๋ฆฌ๊ฒŒ์ดํŠธ์™€ ๋ฐ์ดํ„ฐ์†Œ์Šค ์—ญํ• ์„ ๋ถ„๋ฆฌํ•˜๋ ค๊ณ  ์‹œ๋„
  • ๋ธ๋ฆฌ๊ฒŒ์ดํŠธ์™€ ๋ฐ์ดํ„ฐ์†Œ์Šค ์—ญํ• ์„ ํ•˜๋Š” HolidaysManager๊ฐ์ฒด ๋งŒ๋“ฆ
  • holidaysManager๋ฅผ MainViewController(์ตœ์ƒ์œ„๋ทฐ์ปจ)์—์„œ favoriteCell์„ ๋งŒ๋“ค๋•Œ setData()ํ•จ์ˆ˜์— ๋„˜๊ฒจ์ฃผ๊ณ , ํ•จ์ˆ˜๋‚ด๋ถ€์—์„œ ํ•˜์œ„ ์ฝœ๋ ‰์…˜๋ทฐ(holidaysCollectionView)์˜ ๋ธ๋ฆฌ๊ฒŒ์ดํŠธ๋ฅผ ์ง€์ •ํ•ด์ฃผ์—ˆ๋‹ค.
// MainViewController
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

    let martList = FavoriteList.shared().martList()
    let cell = favoritesCollectionView.dequeueReusableCell(withReuseIdentifier: MainViewController.favoriteCellID, for: indexPath) as! FavoriteCell
    let holidaysManager = HolidaysCollecionViewManager(dateData: martList[indexPath.row].holidays)
    cell.setData(branch: martList[indexPath.row], holidaysManager: holidaysManager)

// FavoriteCell
func setData<T: UICollectionViewDataSource & UICollectionViewDelegate & UICollectionViewDelegateFlowLayout>(branch: Branch, holidaysManager: T) {
    title.text = "\(branch.martType) \(branch.branchName)"
    // holidayDateCollectionView ์„ธํŒ…
    holidaysCollectionView.delegate = holidaysManager
    holidaysCollectionView.dataSource = holidaysManager
    holidaysCollectionView.reloadData()

}

// HolidayManager
class HolidaysCollecionViewManager: NSObject, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {

    var dateData: [String]

    init(dateData: [String]) {
        self.dateData = dateData
    }

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.dateData.count
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "holidaysCell", for: indexPath) as! HolidaysCell
        cell.setData(text: dateData[indexPath.row])
        return cell
    }

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: collectionView.frame.width / 3, height: collectionView.frame.height/2.5)

    }

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 5

    }

}

Comments