Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[๐Ÿฅ’Team-6 / iOS / ์ญ & ์žญ์Šจ] ์ƒ์„ธ ํŽ˜์ด์ง€ ๋ฐ Persistence ๊ตฌํ˜„ #74

Open
wants to merge 128 commits into
base: banchan-code
Choose a base branch
from

Conversation

1song2
Copy link

@1song2 1song2 commented May 3, 2021

์ƒ์พŒํ•œ ์›”์š”์ผ์ž…๋‹ˆ๋‹ค ์ œ์ด์Šจโ˜€๏ธ
์ง€๋‚œ PR ํ”ผ๋“œ๋ฐฑ ๋ฐ ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ ๊ตฌํ˜„์„ ์ฝ”๋“œ์— ๋ฐ˜์˜ํ•ด 2์ฐจ PR์„ ๋“œ๋ฆฝ๋‹ˆ๋‹ค.
ํ”„๋กœ์ ํŠธ ๊ธฐ๊ฐ„์ด ์ข…๋ฃŒ๋˜๊ณ  PR ๋“œ๋ฆฌ๋Š”๋งŒํผ ์ œ์ด์Šจ ์‹œ๊ฐ„๋˜์‹ค ๋•Œ ๊ฐ€๋Šฅํ•˜์‹ ๋งŒํผ๋งŒ ์—ฌ์œ ๋กญ๊ฒŒ ํ”ผ๋“œ๋ฐฑ ํ•ด์ฃผ์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”๐Ÿ™
โ€‹

์ž‘์—… ๋ชฉ๋ก

์ง€๋‚œ PR ํ”ผ๋“œ๋ฐฑ ๋ฐ˜์˜

  • FetchDishesUseCase์˜ RequestValue์—์„œ ๋ถˆํ•„์š”ํ•œ ๊ฐ’์„ ์ œ๊ฑฐ (Category ์ „์ฒด ๋Œ€์‹  Category์˜ name ์†์„ฑ๋งŒ ์š”์ฒญ)
  • DishCell์—์„œ ๋„คํŠธ์›Œํฌ ๊ด€๋ จ logic ์ œ๊ฑฐ
  • DishesListItemViewModel ๋‚ด๋ถ€ ์†์„ฑ์„ Dish entity๋กœ ๋Œ€์ฒด
  • reloadData ๋Œ€์‹  reloadSections๋กœ ํŠน์ • ์„น์…˜์˜ ๋ฐ์ดํ„ฐ๋งŒ ์—…๋ฐ์ดํŠธ
  • Test ์ฝ”๋“œ ์ž‘์„ฑ

๊ธฐ๋Šฅ ๊ตฌํ˜„

  • ๋„คํŠธ์›Œํฌ ์š”์ฒญ์œผ๋กœ ๋ฐ›์•„์˜จ ๋ฐ˜์ฐฌ ๋ชฉ๋ก์„ Persistence๋กœ ์ €์žฅ (Realm ์ด์šฉ)
  • ๋ฐ˜์ฐฌ ๋ฐฐ์†ก ์ •๋ณด, ์ˆ˜๋Ÿ‰ ์„ ํƒ, ์ƒ์„ธ ์ด๋ฏธ์ง€ ๋“ฑ์„ ๋Œ€์‘ํ•  ์ˆ˜ ์žˆ๋Š” ์ƒ์„ธ ํŽ˜์ด์ง€ ๊ตฌํ˜„
  • ๋ฉ”์ธ ํŽ˜์ด์ง€์—์„œ ํŠน์ • ์…€์„ ํƒญํ•˜๋ฉด ํ•ด๋‹น ์ƒ์„ธ ํŽ˜์ด์ง€๋กœ ์ด๋™

๊ตฌ์กฐ ์„ค๊ณ„ ํ๋ฆ„๋„

  • ๊ฐ ํด๋ž˜์Šค๋ฅผ Diagramํ™” & MVVM ๊ณ„์ธต์— ๋งž๊ฒŒ ๋ถ„๋ฅ˜ ๋งํฌ
    โ€‹

ํ•™์Šต ํ‚ค์›Œ๋“œ

Realm, UIScrollView (Paging), reloadSections
โ€‹

๊ณ ๋ฏผ๊ณผ ํ•ด๊ฒฐ

Realm ๋ฐ์ดํ„ฐ ์ €์žฅ

from @JacksonPk
์ด๋ฒˆ ํ”„๋กœ์ ํŠธ์—์„œ Persistence๋ฅผ ์ด์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๊ณ ์•ˆํ–ˆ๊ณ  DB๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ์œ„ํ•ด Realm์„ ์จ ๋ณด์•˜์Šต๋‹ˆ๋‹ค.
Alamofire์˜ Result๊ฐ’์— ๋”ฐ๋ผ items๋ฅผ ๊ฐ€์ ธ์˜ฌ ์‹œ Realm์— dish๊ฐ’์„ ์ €์žฅํ–ˆ๊ณ , ๋„คํŠธ์›Œํฌ ์—ฐ๊ฒฐ์ด ์•ˆ๋  ์‹œ(WIFI/LTE OFF) Realm์— ์žˆ๋Š” DB๋ฅผ ๋ถˆ๋Ÿฌ์™€ ๋ฉ”์ธ ํŽ˜์ด์ง€์— ๋ณด์—ฌ์ฃผ๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ณ ์•ˆํ–ˆ์Šต๋‹ˆ๋‹ค.
๊ถ๊ธˆํ–ˆ๋˜ ์ ์€ Persistence์— ์žˆ๋Š” ์ด ๋ฐ์ดํ„ฐ๋“ค์„ ๊ณ ์•ˆํ•œ ๋ฐฉ์‹์ฒ˜๋Ÿผ ๊ด€๋ฆฌํ•ด๋„ ๊ดœ์ฐฎ์€ ๊ฒƒ์ธ์ง€, ํ˜น์€ ๋” ๋‚˜์€๋ฐฉ๋ฒ•์ด๋‚˜ ๋‹ค๋ฅธ ์ ‘๊ทผ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค.
โ€‹

reloadSections

from @1song2
์ด๋ฒˆ ํ”„๋กœ์ ํŠธ์˜ ๋ฉ”์ธ๋””์‰ฌ๋ผ๊ณ  ๋ง์”€ํ•ด์ฃผ์‹  reloadSections ๋ถ€๋ถ„์„ ๊ผญ ๊ตฌํ˜„ํ•ด๋ณด๊ณ  ์‹ถ์–ด์„œ ์ง€๋‚œ ์ฃผ๋ง๋™์•ˆ ์‹œ๋„ํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค.
๊ฒฐ๊ณผ์ ์œผ๋กœ ์„ฑ๊ณตํ•˜์ง„ ๋ชปํ–ˆ๋Š”๋ฐ์š”๐Ÿ˜ญ ์‹œ๋„ํ•ด๋ณด๋Š” ๊ณผ์ • ์ค‘์—์„œ ๋Š๋‚€ ์ ์ด ๋ช‡๊ฐ€์ง€ ์žˆ์–ด ์•„๋ž˜ ๊ณต์œ ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

๋ฌธ์ œ ์ƒํ™ฉ ๋ฐ ์‹œ๋„ ๋ฐฉ์•ˆ

  1. [๋ฌธ์ œ] items๋Š” section์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— reloadSections(_:)์— ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋‹ด์„ section index๋ฅผ ์•Œ ์ˆ˜ ์—†์Œ
  • [์‹œ๋„] category์— sectionIndex์™€ items๋ฅผ ์†์„ฑ๊ฐ’์œผ๋กœ ์ถ”๊ฐ€
  • category๋ฅผ observeํ•ด items์— ๋ณ€๋™ ์‚ฌํ•ญ์ด ์žˆ์„ ์‹œ ํ•ด๋‹น sectionIndex๋กœ reloadSections ์‹œ๋„
  1. [๋ฌธ์ œ] 1๋ฒˆ๊ณผ ๊ฐ™์ด ์ˆ˜์ • ํ›„ ์ฝ˜์†”์— ์•„๋ž˜์™€ ๊ฐ™์€ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€ ๋ฐœ์ƒ (ํ”„๋กœ๊ทธ๋žจ์ด ๋™์ž‘์€ ๋จ)
[UICollectionView] Invalid update: invalid number of items in section 0. 
The number of items contained in an existing section after the update (11)
must be equal to the number of items contained in that section before the update (0),
plus or minus the number of items inserted or deleted from that section (0 inserted, 0 deleted)
and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out). - will perform reloadData.
UICollectionView instance: <UICollectionView: 0x7fe58382de00; frame = (0 47; 390 763); clipsToBounds = YES;
autoresize = RM+BM; gestureRecognizers = <NSArray: 0x600003cf34e0>; layer = <CALayer: 0x6000032d77e0>; 
contentOffset: {0, 0}; contentSize: {390, 294}; adjustedContentInset: {0, 0, 0, 0}; layout: <UICollectionViewFlowLayout: 0x7fe582f10c00>;
dataSource: <BanchanCode.MainPageCollectionViewDataSource: 0x6000032898e0>>;
currentUpdate: [UICollectionViewUpdate - 0x7fe581c124d0: old:<UICollectionViewData: 0x600000d884b0> new<UICollectionViewData: 0x600000d8c000>
items:<(
    "DS(1)",
    "IS(1)"
)>]
  • [์‹œ๋„] ๋ธŒ๋ ˆ์ดํฌ ํฌ์ธํŠธ ๋“ฑ์„ ํ†ตํ•ด ํŒŒ์•…ํ•œ ๊ฒฐ๊ณผ, ๋‘ section์ด ๋™์‹œ์— ์—…๋ฐ์ดํŠธ ๋˜๋Š” ์‹œ์ ์— ํ•ด๋‹น ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•จ์„ ํŒŒ์•… (๋™์‹œ์„ฑ ์ด์Šˆ?)
  • reloadSections ์‚ฌ์šฉ์‹œ, ํ˜„์žฌ reloadSections๋ฅผ ์‹œ๋„ํ•˜๋Š” section ์™ธ์—๋Š” ๋ณ€๋™์‚ฌํ•ญ์ด ๋ฐœ์ƒํ•ด์„œ๋Š” ์•ˆ๋จ์„ ์ดํ•ด
  • ํ•ด๋‹น ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด Xcode ์ž์ฒด์—์„œ reloadSections ๋Œ€์‹  reloadData๋ฅผ ๋Œ€์‹  ํ˜ธ์ถœ
    โ€‹
    ํ•ด๋‹น ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•œ ๋‹ค๋ฅธํŒ€ ๋™๋ฃŒ๋ถ„๋“ค ์ฝ”๋“œ๋ฅผ ์ฐธ๊ณ ํ•ด ์ˆ˜์ •ํ•˜๊ณ ์ž ์‹œ๋„๋Š” ํ•ด๋ณด์•˜์ง€๋งŒ, ์•„๋ฌด๋ž˜๋„ ์–ด๋Š ์ •๋„ ๊ฐœ๋ฐœ์ด ์ง„ํ–‰๋œ ์ฝ”๋“œ์˜ ์ „์ฒด ๊ตฌ์กฐ๋ฅผ ๋œฏ์–ด๊ณ ์ณ์•ผ ํ•˜๋Š” ๋ถ€๋ถ„์ด๊ธฐ์— ์‰ฝ์ง€๊ฐ€ ์•Š์•˜์Šต๋‹ˆ๋‹ค๐Ÿ˜ข
  • ์ˆ˜์ •์„ ์‹œ๋„ํ–ˆ๋‹ค ํฌ๊ธฐํ•œ ๋ถ€๋ถ„
    • main, soup, side๋ฅผ ๊ฐ๊ฐ์˜ view model๋กœ ๋‘๋Š” ๋Œ€์‹  ํ•˜๋‚˜์˜ view model๋กœ ๋ฌถ๊ณ  ๋‚ด๋ถ€์— ๋ฐฐ์—ด ํ˜น์€ ๋”•์…”๋„ˆ๋ฆฌ๋กœ main, soup, side๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋„๋ก ํ•จ
    • Observable ๋Œ€์‹  closure๋ฅผ ์‚ฌ์šฉํ•ด items ๊ฐ’์— ๋ณ€ํ™”๊ฐ€ ์ƒ๊ธฐ๋Š” ์‹œ์ ์— ํ•ด๋‹น ์นดํ…Œ๊ณ ๋ฆฌ ๊ฐ’์„ view controller๋กœ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•จ

๊ผญ ํ•ด๋ณด๋ฉด ์ข‹๊ฒ ๋‹ค๊ณ  ํŒ์„ ์ฃผ์‹  ๋ถ€๋ถ„์ธ๋ฐ ์™„์ „ํžˆ ๊ตฌํ˜„ํ•˜์ง€ ๋ชปํ•˜๊ณ  ๋„˜์–ด๊ฐ€ ๋„ˆ๋ฌด ์•„์‰ฝ์ง€๋งŒ,
๊ทธ๋ž˜๋„ ํ•ด๊ฒฐ์„ ์œ„ํ•ด ์—ฌ๋Ÿฌ๊ฐ€์ง€๋กœ ์‹œ๋„ํ•ด๋ณด๋ฉด์„œ ๋Š๋ผ๊ณ  ๋ฐฐ์šฐ๋Š” ๊ฒŒ ์ฐธ ๋งŽ์•˜์Šต๋‹ˆ๋‹ค. ์ œ์ด์Šจ ๊ฐ์‚ฌ๋“œ๋ ค์š”.
(๋ง์”€์ฃผ์‹œ๊ธฐ ์ „๊นŒ์ง„ reloadSections๋ผ๋Š” ๋ฉ”์†Œ๋“œ๊ฐ€ ์กด์žฌํ•˜๋Š”์ง€๋„ ๋ชฐ๋ž์—ˆ์Šต๋‹ˆ๋‹ค๐Ÿ˜ญ)
์ถ”ํ›„ ๊ธฐํšŒ๊ฐ€ ๋œ๋‹ค๋ฉด ๋ฐ˜์ฐฌ ํ”„๋กœ์ ํŠธ๋ฅผ ์•„์˜ˆ ์ฒ˜์Œ๋ถ€ํ„ฐ ๊ตฌํ˜„ํ•˜๋ฉด์„œ ํ•ด๋‹น ๊ธฐ๋Šฅ์„ ๋‹ค์‹œ ์‹œ๋„ํ•ด๋ณด๊ณ  ์‹ถ๋„ค์š”!
โ€‹
2์ฃผ๋™์•ˆ ์ •๋ง ๊ณ ์ƒ ๋งŽ์œผ์…จ๊ณ  ๊ฐ์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค. ์ƒˆ๋กœ์šด ํ•œ์ฃผ, ํ•œ๋‹ฌ ํž˜๋‚ด์„œ ์‹œ์ž‘ํ•˜์‹œ๊ธธ ๋ฐ”๋ž„๊ฒŒ์š”!

JacksonPk and others added 30 commits April 23, 2021 17:21
@rla36 rla36 added the review-iOS iOS ๋ฆฌ๋ทฐ label May 3, 2021
@rla36 rla36 requested a review from ehgud0670 May 3, 2021 01:48
@ehgud0670
Copy link

๋„ต ใ…Žใ…Ž ๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค. ์ฒœ์ฒœํžˆ ์‚ดํŽด๋ณด๊ณ  ์ฝ”๋ฉ˜ํŠธ ๋“œ๋ฆด๊ฒŒ์š”!

Copy link

@ehgud0670 ehgud0670 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ถ๊ธˆํ–ˆ๋˜ ์ ์€ Persistence์— ์žˆ๋Š” ์ด ๋ฐ์ดํ„ฐ๋“ค์„ ๊ณ ์•ˆํ•œ ๋ฐฉ์‹์ฒ˜๋Ÿผ ๊ด€๋ฆฌํ•ด๋„ ๊ดœ์ฐฎ์€ ๊ฒƒ์ธ์ง€, ํ˜น์€ ๋” ๋‚˜์€๋ฐฉ๋ฒ•์ด๋‚˜ ๋‹ค๋ฅธ ์ ‘๊ทผ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค.

โ€‹=>๋„ต, ์ง€๊ธˆ๊ณผ ๊ฐ™์ด ์ž‘์„ฑํ•ด๋„ ๊ดœ์ฐฎ์„ ๊ฒƒ ๊ฐ™๋„ค์š”! primaryKey๋„ ์ž˜์“ฐ๊ณ  ๊ณ„์‹œ๊ณ ์š”. ์ด ํ”„๋กœ์ ํŠธ ๋ง๊ณ  ๋” ๋ณต์žกํ•œ ์ƒํ™ฉ์ด ์žˆ์–ด์•ผ ๋” ๋‚˜์€ ๋ฐฉ๋ฒ•์ด ๋ญ๊ฐ€ ์žˆ์„์ง€ ๊ณ ๋ฏผํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ๋ฐฑ์—”๋“œ๋ถ„๋“ค์—๊ฒŒ DB ์ž‘์„ฑํ•˜๊ธฐ ๊นŒ๋‹ค๋กœ์šด ์ƒํ™ฉ์œผ๋กœ ์–ด๋–ค๊ฒŒ ์žˆ๋Š”์ง€ ์งˆ๋ฌธํ•ด๋ณด์„ธ์š” ใ…Žใ…Ž
=> ๋‹ค๋งŒ ์‚ฌ์šฉํ•˜๋Š” ์ „์ฒด์ ์ธ ๋กœ์ง์ด ํšจ์œจ์ ์ด์ง€ ๋ชปํ•œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๋ชจ๋ฐ”์ผ์—์„œ DB๋Š” ๋„คํŠธ์›Œํฌ ์‚ฌ์šฉ๋Ÿ‰์„ ์ค„์ด๊ธฐ ์œ„ํ•ด์„œ๋„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋งจ ์ฒ˜์Œ์—๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ๋ฐ›์•„ DB์— ์ €์žฅํ•˜๊ณ , ๊ทธ ์ดํ›„์—๋Š” DB์— ๋ฐ์ดํ„ฐ๊ฐ€ ์žˆ๋‹ค๋ฉด ๋ฐ์ดํ„ฐ๋ฅผ ์„œ๋ฒ„๋กœ ์š”์ฒญํ•˜์ง€ ์•Š๊ณ  DB์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์–ด๋–จ๊นŒ์š”? ๊ทธ๋ฆฌ๊ณ  ์—…๋ฐ์ดํŠธ Interval๋ฅผ ๋‘ฌ์„œ ์‹œ๊ฐ„์ด ์ง€๋‚˜ ๋ฐ์ดํ„ฐ๋ฅผ ์—…๋ฐ์ดํŠธ ํ•ด์•ผ ํ•˜๋ฉด ๋‹ค์‹œ ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ๋ฐ์ดํ„ฐ๋ฅผ ์š”์ฒญํ•˜๋Š”๊ฑฐ์ฃ .

์ด๋ฒˆ ํ”„๋กœ์ ํŠธ์˜ ๋ฉ”์ธ๋””์‰ฌ๋ผ๊ณ  ๋ง์”€ํ•ด์ฃผ์‹  reloadSections ๋ถ€๋ถ„์„ ๊ผญ ๊ตฌํ˜„ํ•ด๋ณด๊ณ  ์‹ถ์–ด์„œ ์ง€๋‚œ ์ฃผ๋ง๋™์•ˆ ์‹œ๋„ํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค.

=> ์ด ๋ถ€๋ถ„ ๊ตฌํ˜„ํ•ด ๋ณด์‹œ๋ ค๊ณ  ๊ณ ์ƒ ๋งŽ์œผ์…จ์Šต๋‹ˆ๋‹ค. ๊ตฌํ˜„ํ•˜๋ ค๊ณ  ์ฃผ๋ง์—๋„ ์ฝ”๋”ฉํ•˜์‹œ๊ณ  ์ •๋ง ๋Œ€๋‹จํ•˜์‹œ๋„ค์š” ๐Ÿ’ฏ ์ €๋„ ์ด ๋ถ€๋ถ„ ๊ตฌํ˜„ ๋ชปํ•ด์„œ ์˜†์— ์นœ๊ตฌํ•œํ…Œ๋„ ๋ฌผ์–ด๋ณด๊ณ  ๊ทธ๋žฌ์–ด์š” ใ… ใ…  ใ…‹ใ…‹. ๊ทธ๋ฆฌ๊ณ  ์ด์ „ ๊ธฐ์ˆ˜๋“ค ์ค‘์—์„œ๋„ ์ด๊ฑฐ ๋‹ค์‹œ ๊ตฌํ˜„ํ•ด๋ณด๋ผ๊ณ  ํ•˜๋ฉด ๋ชปํ•  ์‚ฌ๋žŒ๋“ค๋„ ๊ฝค ์žˆ์„๊ฑฐ์—์š”. ์–ด๋ ค์šด ๋ถ€๋ถ„์ด๋‹ˆ ๋„ˆ๋ฌด ์ƒ์‹ฌํ•˜์ง€ ์•Š์œผ์…จ์œผ๋ฉด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  reloadSections๋Š” ์ด์ „์— ์•ˆ์ผ์œผ๋ฉด ๋‹น์—ฐํžˆ ๋ชจ๋ฅด๋Š” ๊ฑฐ๋‹ˆ๊น ์‹ ๊ฒฝ์“ฐ์ง€๋งˆ์„ธ์š” ใ…Žใ…Ž
=> reloadSections ์ด ๋ถ€๋ถ„ ๊ทธ๋ž˜์„œ ์ง€๊ธˆ ์ฝ”๋“œ๋กœ ์ œ๊ฐ€ ๊ตฌํ˜„ํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค. ์ด ๋ถ€๋ถ„ ๋”ฐ๋กœ ์˜คํ”„๋ผ์ธ์œผ๋กœ ์ œ๊ฐ€ ํ•™์›์— ๊ฐ€์„œ ์„ค๋ช… ํ•ด๋“œ๋ฆด์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์€๋ฐ ์„ค๋ช…ํ•ด๋“œ๋ฆด๊นŒ์š”? ๊ธ€๋กœ๋งŒ ์„ค๋ช…ํ•ด๋“œ๋ฆฌ๋ ค๊ณ  ํ•˜๋‹ˆ ๋ณต์žกํ•˜๋„ค์š” ใ…‹.ใ…‹ ๋ต ์ˆ˜ ์žˆ์œผ๋ฉด ๋‹ค๋ฅธ ๋ถ€๋ถ„๋“ค๋„ ์ถ”๊ฐ€๋กœ ๋” ์„ค๋ช…๋“œ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค!

  • ์ถ”๊ฐ€๋กœ ์งง์€ ์‹œ๊ฐ„์•ˆ์— DetailPageVC๊นŒ์ง€ ๊ตฌํ˜„ํ•˜์‹œ๊ณ  ๋Œ€๋‹จํ•˜์‹œ๋„ค์š”! ๊ณ ์ƒ๋งŽ์œผ์…จ์Šต๋‹ˆ๋‹ค. ๐Ÿ‘

p.s ๋„ˆ๋ฌด ๋Šฆ๊ฒŒ ํ”ผ๋“œ๋ฐฑ์„ ๋“œ๋ ค ์ฃ„์†กํ•˜๋„ค์š”... ใ…œ.ใ…œ ๋ฐ˜์˜์€ ์•ˆํ•˜์…”๋„ ๋˜๋‹ˆ ํ”ผ๋“œ๋ฐฑ๋งŒ ๋ด์ฃผ์‹œ๊ณ  ์ฝ”๋ฉ˜ํŠธ ๋‹ฌ์•„์ฃผ์„ธ์š” ใ…Žใ…Ž. ๋‘ ๋ถ„๋„ ํ”ผ๋“œ๋ฐฑ ํ™•์ธํ•˜์…จ์œผ๋ฉด ๋จธ์ง€ ํ•˜์…”๋„ ๋ฉ๋‹ˆ๋‹ค.

let prices = List<Int>()
let badges = List<String>()

convenience init(id: Int, name: String, contents: String, imageURL: String, categoryName: String) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

covenience init์„ ์“ฐ์‹  ์ด์œ ๊ฐ€ ๋”ฐ๋กœ ์žˆ์„๊นŒ์š”? ํŠน๋ณ„ํ•œ ์ด์œ ๊ฐ€ ์—†์œผ์‹œ๋‹ค๋ฉด ๊ทธ๋ƒฅ init์„ ์จ๋„ ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

Comment on lines +22 to +28
self.init()
self.id = id
self.name = name
self.contents = contents
self.imageURL = imageURL
self.categoryName = categoryName
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด ๋ถ€๋ถ„์—์„œ prices ์™€ badges๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š”๊ฒŒ ๊น”๋”ํ•˜๊ฒ ๋„ค์š”. ๊ทธ๋ฆฌ๊ณ  ์ฐพ์•„๋ณด๋‹ˆ append(objectsIn:) ๋ผ๋Š” ๊ฒƒ๋„ ์žˆ๋Š”๋ฐ ์จ๋ณด์‹œ๋Š” ๊ฒŒ ์–ด๋–จ๊นŒ์š”?

Comment on lines 42 to 44
mainPageDataSource?.viewModels = viewModels
mainPageDelegate?.viewModels = viewModels

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mainVC์—๋„ viewModels๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๊ณ  datasource์™€ delegate์—๋„ viewModels๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋„ค์š”.
์ด๋ ‡๊ฒŒ ์—ฌ๋Ÿฌ ๊ฐ์ฒด๊ฐ€ ๊ณตํ†ต๋œ viewModels๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๊ฒƒ๋ณด๋‹จ ํ•˜๋‚˜์˜ ๊ฐ์ฒด๋งŒ ํ”„๋กœํผํ‹ฐ๋กœ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๊ฒƒ์ด ๋” ๊น”๋”ํ•˜๊ณ  ๋กœ์ง์ด ๋‹จ์ˆœํ•˜์—ฌ ์ฝ”๋“œ๋ฅผ ํŒŒ์•…ํ•˜๊ธฐ ์ข‹์Šต๋‹ˆ๋‹ค.
์ตœ์†Œํ•œ ์ด ํ”„๋กœ์ ํŠธ์—์„œ๋Š” ๋‹จ ํ•˜๋‚˜์˜ ๊ฐ์ฒด๋งŒ์ด ๊ฐ€์ง€๊ฒŒ ํ•  ์ˆ˜ ์žˆ์œผ๋‹ˆ ์—ฌ์œ  ์žˆ์œผ์‹ค๋•Œ ์‹œ๋„ํ•ด๋ณด์„ธ์š”.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ง€๊ธˆ ๊ฐ„๋‹จํžˆ ์ƒ๊ฐํ•ด๋ณด๊ธฐ๋กœ๋Š” delegate๋‚˜ dataSource๋ฅผ ๋ณ„๋„์˜ ๊ฐ์ฒด๋กœ ๋ถ„๋ฆฌํ•˜์ง€ ์•Š๊ณ , MainPageViewController๋ฅผ extendํ•ด ์‚ฌ์šฉํ•œ๋‹ค๋ฉด viewModels๋ฅผ ํ•˜๋‚˜๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์ง€ ์•Š์„๊นŒ ์‹ถ์€ ์ƒ๊ฐ์ด ๋“œ๋„ค์š”!

viewController๋ฅผ ๊ฐ€๋ณ๊ฒŒ ์‚ฌ์šฉํ•˜๊ณ ์ž ํŒŒ์ผ์„ ๋ถ„๋ฆฌํ•ด ์ž‘์„ฑํ•œ ๊ฒƒ์ด์—ˆ๋Š”๋ฐ, ๋ง์”€ํ•˜์‹ ๋Œ€๋กœ ์—ฌ๋Ÿฌ ๊ฐ์ฒด๊ฐ€ viewModels๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๊ฒƒ์€ ํ™•์‹คํžˆ ํ—ท๊ฐˆ๋ฆฌ๊ณ  ๊น”๋”ํ•˜์ง€ ์•Š์€ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค๐Ÿค”

๋˜ ๋‹ค๋ฅธ ๊ฐœ์„  ๋ฐฉ๋ฒ•์ด ์žˆ์„์ง€๋„ ์ข€ ๋” ๊ณ ๋ฏผํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!


class MainPageViewController: UIViewController {

@IBOutlet weak var dishCollectionView: UICollectionView!
private var mainPageDelegate: MainPageCollectionViewDelegate?
private var mainPageDataSource: MainPageCollectionViewDataSource?
private var viewModels: [DishesViewModel]!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

viewModels ๋ฐฐ์—ด(์ž๋ฃŒ๊ตฌ์กฐ)๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” CategoryViewModel ๊ฐ์ฒด๋ฅผ ๋งŒ๋“œ๋Š” ๊ฑด ์–ด๋–จ๊นŒ์š”?
์ด๋Ÿฌํ•œ ๊ฐ์ฒด๊ฐ€ ์žˆ์œผ๋ฉด ๋ฉ”์†Œ๋“œ๋กœ ๋” ์ถ”์ƒํ™” ๊ฐ€๋Šฅํ• ๊ฒƒ ๊ฐ™์•„์š”.

ํŒ

  • ํ•˜๋‚˜์˜ ์ด์ฒด์ ์ธ ๋ทฐ๋ชจ๋ธ์„ ๋จผ์ € ์ƒ๊ฐํ•˜๊ณ  ์•ˆ์— ์„ธ๋ถ€์ ์ธ ๋ทฐ๋ชจ๋ธ์„ ์ž‘์„ฑํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•˜์‹œ๋ฉด ์‰ฝ๊ฒŒ ์‰ฝ๊ฒŒ ๊ฐ์ฒด๋ฅผ ๋งŒ๋“œ์‹ค ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์•„์š”.
  • ๋งจ ์ฒ˜์Œ์— ๋ทฐ๋ชจ๋ธ์„ ๊ตฌํ˜„ํ•˜์‹ค๋•Œ ํ•˜๋‚˜์˜ VC์—์„œ ์ œ์ผ ํฐ ๋ทฐ๋ชจ๋ธ ํ•˜๋‚˜๋ฅผ ๋งŒ๋“ค๊ณ  ํ”„๋กœํผํ‹ฐ๋กœ ๋ชจ๋ธ ๊ฐ’๋งŒ ๋‘๊ณ  ๋ฉ”์†Œ๋“œ๋งŒ ์ถ”๊ฐ€ํ•˜์‹œ๋Š” ๊ฑธ ์ถ”์ฒœ๋“œ๋ฆฝ๋‹ˆ๋‹ค. ๊ทธ ๋‹ค์Œ์— ์„ธ๋ถ€์ ์ธ ๋ทฐ๋ชจ๋ธ์„ ์ฐจ๊ทผ์ฐจ๊ทผ ๊ตฌํ˜„ํ•˜๋Š”๊ฑฐ์ฃ .

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋„ค ์ œ์ด์Šจ ์ฃผ์‹  ์˜๊ฒฌ์— ๊ณต๊ฐํ•ฉ๋‹ˆ๋‹ค!
์ž๋ฃŒ๋ฅผ ๋งŽ์ด ์ฐพ์•„๋ณธ ๊ฒƒ์€ ์•„๋‹ˆ์ง€๋งŒ ์ด๋ ‡๊ฒŒ viewModel์„ ์—ฌ๋Ÿฌ๊ฐœ ๊ฐ€์ง€๊ณ  ์žˆ๊ธฐ ๋ณด๋‹ค๋Š” ํฌ๊ฒŒ ์•„์šฐ๋ฅด๋Š” ํ•˜๋‚˜์˜ viewModel์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ผ๋ฐ˜์ ์ธ ๊ฒƒ ๊ฐ™๋‹ค๋Š” ๋Š๋‚Œ์„ ๋ฐ›์•˜์–ด์š”.
๋‹ค๋งŒ ๊ฐœ์„ ์ด ์ƒ๊ฐ์ฒ˜๋Ÿผ ๋˜์ง€ ์•Š์•„ ๊ทธ๋ƒฅ ํ˜„์žฌ์˜ ๊ตฌ์กฐ๋กœ ๋‘๊ณ  ์•„์‰ฌ์›€๋งŒ ๋Š๋ผ๊ณ  ์žˆ์—ˆ๋Š”๋ฐ,
ํŒ ์ฃผ์‹  ๋‚ด์šฉ์„ ์ฐธ๊ณ ํ•ด ํ•œ๋ฒˆ ์ˆ˜์ •ํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!

Comment on lines 80 to 84
viewModel.category.observe(on: self) { [weak self] category in
DispatchQueue.main.async {
self?.updateSection(at: category.sectionIndex)
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

observe ๋ฉ”์†Œ๋“œ๊ฐ€ category์—์„œ๋งŒ ์“ฐ์ด๋Š” ๊ตฐ์š”!
items์˜ observe ๋ฉ”์†Œ๋“œ๊ฐ€ ์“ฐ์ด์ง€ ์•Š๋Š”๋‹ค๋ฉด items๋Š” Observable<[DishesItemViewModel]> ํƒ€์ž…์ด ์•„๋‹Œ [DishesItemViewModel] ์ด ํƒ€์ž…์ด์–ด๋„ ๋  ๊ฒƒ ๊ฐ™๋„ค์šฉ

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reloadSections๋ฅผ ์‹œ๋„ํ•ด๋ณด๋Š” ๊ณผ์ •์—์„œ category๋ฅผ ๊ธ‰ํ•˜๊ฒŒ ์ถ”๊ฐ€ํ•˜๋‹ค ๋ณด๋‹ˆ ํ•„์š” ์—†๋Š” ๋ถ€๋ถ„์—์„œ Observable์ด ์‚ฌ์šฉ๋˜๊ณ  ์žˆ๋Š” ๊ฑธ ๋†“์ณค๋„ค์š”. PR ์ „์— ์ž‘์„ฑํ–ˆ๋˜ ์ฝ”๋“œ๋ฅผ ์ข€๋” ๊ผผ๊ผผํžˆ ์‚ดํ”ผ๋Š” ์Šต๊ด€์„ ๋“ค์ด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!

viewModel.category.observe(on: self) { [weak self] _ in self?.updateItems() }
viewModel.items.observe(on: self) { [weak self] _ in self?.updateItems() }
viewModel.category.observe(on: self) { [weak self] category in
DispatchQueue.main.async {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DispatchQueue.main.async ์ด ๋ถ€๋ถ„ ์ฃผ์„์ฒ˜๋ฆฌํ•ด๋„ UI๋ฅผ ๋ฉ”์ธ์Šค๋ ˆ๋“œ์—์„œ ์ฒ˜๋ฆฌํ•˜๊ณ  ์žˆ์ง€ ์•Š๋‹ค๋Š” ๊ฒฝ๊ณ ๊ฐ€ ์•ˆ๋œฐ๊ป๋‹ˆ๋‹ค. ์™œ ๊ทธ๋Ÿฐ์ง€ ๊ณ ๋ฏผํ•ด๋ณด์„ธ์š” ใ…Žใ…Ž

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์œ„์— ํ”ผ๋“œ๋ฐฑ ์ฃผ์…จ๋˜ responseDecodable๋ถ€ํ„ฐ ๊ณ„์† ๋ฉ”์ธ์—์„œ ์ฒ˜๋ฆฌ๋ฅผ ํ•˜๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์ผ๊นŒ์š”?๐Ÿ‘€

Comment on lines 87 to 89
private func updateSection(at index: Int) {
self.dishCollectionView.reloadSections(IndexSet(integer: index))
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DispatchQueue.main.async๋ฅผ ์—ฌ๊ธฐ์— ์˜ฎ๊ฒจ๋„ ๋˜์ง€ ์•Š์„๊นŒ์š”?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•„๋ž˜ DispatchQueue ๊ด€๋ จ ์ฃผ์…จ๋˜ ๋‹ค๋ฅธ ํ”ผ๋“œ๋ฐฑ๊ณผ ์ข…ํ•ฉํ•ด์„œ ์ƒ๊ฐํ•ด๋ณด๋ฉด,
์ข€๋” ์ง์ ‘์ ์œผ๋กœ UI๋ฅผ ์ฒ˜๋ฆฌํ•ด์ฃผ๋Š” ๋ถ€๋ถ„์—์„œ DispatchQueue๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ๋‚ซ๋‹ค๋Š” ๋ง์”€์ด์‹ค๊นŒ์š”?
์•„์ง ์™„๋ฒฝํžˆ ๊ฐ์ด ์˜ค์ง„ ์•Š์•„์„œ ์•„๋ž˜ ๋ง์”€ํ•ด์ฃผ์‹  ๊ฒƒ์ฒ˜๋Ÿผ ์Šค๋ ˆ๋“œ๊ฐ„ ์—ญํ• ์„ ์ข€๋” ํ•™์Šตํ•ด๋ณด๊ณ  ๊ทธ๋ถ€๋ถ„ ๊ณ ๋ฏผํ•ด ์ฝ”๋“œ ์ž‘์„ฑํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!

}

class RealmManager: RealmOperations {
let realm = try! Realm()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forcedunwrapping ์€ ์ข‹์ง€ ์•Š์•„์š”. ์•„์˜ˆ ์‚ฌ์šฉ ์•ˆํ•˜์‹œ๋Š” ๊ฑธ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค.
try? ์„ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ do-try-catch ๊ตฌ๋ฌธ์œผ๋กœ ์—๋Ÿฌ๋ฅผ ์žก๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ํŠœํ† ๋ฆฌ์–ผ๋Œ€๋กœ ๋”ฐ๋ผ๋งŒ ํ•˜๋‹ค๋ณด๋‹ˆ force๋ฅผ ์ด์šฉํ–ˆ์Šต๋‹ˆ๋‹ค. ์•ž์œผ๋กœ๋Š” try catch๋กœ ๊ตฌํ˜„ํ•ด๋ณด๋Š” ์Šต๊ด€์„ ํ‚ค์šฐ๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!

Comment on lines +29 to +31
try! realm.write {
realm.add(dishDB)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ try? ์„ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ do-try-catch ๊ตฌ๋ฌธ์œผ๋กœ ์—๋Ÿฌ๋ฅผ ์žก๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.
  • ๋˜ ์Šค์œ„ํ”„ํŠธ์—์„œ Error๋ž€ ์ฒ˜๋ฆฌ๊ฐ€๋Šฅํ•œ ์—๋Ÿฌ๋ฅผ ๋งํ•ฉ๋‹ˆ๋‹ค. ์Šค์œ„ํ”„ํŠธ์˜ Error๋Š” ์ž๋ฐ”, ์˜ค๋ธŒ์ ํ‹ฐ๋ธŒ์”จ์˜ Error ๋ฐ Exception์™€๋Š” ๋˜ ์–ด๋–ป๊ฒŒ ๋‹ค๋ฅธ์ง€ ๊ณต๋ถ€ํ•˜์‹œ๋ฉด Swift๋ฅผ ๋ณด๋‹ค ๊นŠ๊ฒŒ ์ดํ•ดํ•˜์‹ค ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์•„์š”.
    • ์ด ๋ถ€๋ถ„์— ๋Œ€ํ•ด์„œ๋Š” ์ œ๊ฐ€ ์Šคํ„ฐ๋””ํ•˜๋ฉด์„œ ์ž‘์„ฑํ•œ ๊ธ€์ด ์žˆ๋Š”๋ฐ ํ•œ๋ฒˆ ๋ณด์‹œ๋Š” ๊ฒƒ๋„ ์ข‹์„๊ฒƒ ๊ฐ™์•„์š” ใ…‹ใ…‹ใ…‹ ใ…Žใ…Ž. ๋น„ํŒ์€ ํ™˜์˜์ž…๋‹ˆ๋‹ค!!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฒˆ ๊ธฐํšŒ์— ์ €๋„ Result<T,Error> ์— ๋Œ€ํ•œ ๊ฐœ๋…์„ ์‚ด์ง ๋ง›๋ณด์•˜๋Š”๋ฐ( ๋„คํŠธ์›Œํฌ ์—ฐ๊ฒฐ์ด ์•ˆ๋์„ ๋•Œ ์—๋Ÿฌ ์ฒ˜๋ฆฌ๋ฅผ ์ด์šฉํ•ด์„œ DB์˜ ์•„์ดํ…œ์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•ด์„œ) ์ œ์ด์Šจ์ด ์จ์ฃผ์‹  ๊ธ€์„ ํ•œ๋ฒˆ ์ฝ์–ด๋ณด๊ณ  ์ดํ•ดํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!

Copy link

@ehgud0670 ehgud0670 May 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•„ ๋„ต, ๊ธ€์ด ์ข€ ์ •์ œ๋˜์–ด ์žˆ์ง„ ์•Š์•„์š” ใ…‹ใ…‹ใ…‹

}
}

private func refreshView() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DispatchQueue.main.async๊ฐ€ observe์— ์žˆ๋Š”๊ฒƒ๋ณด๋‹ค refreshView์ฒ˜๋Ÿผ UI์ฒ˜๋ฆฌํ•˜๋Š” ๋ฉ”์†Œ๋“œ์— ์œ„์น˜ํ•˜๋Š”๊ฒŒ ์ž๋ฆฌ์žก๋Š” ๊ฒŒ ๋” ๋‚ซ์ง€ ์•Š์„๊นŒ์š”? ๋ฉ”์ธ ์Šค๋ ˆ๋“œ๊ฐ€ ๋‹ค๋ฅธ ์Šค๋ ˆ๋“œ์™€ ๋‹ค๋ฅด๊ฒŒ ์–ด๋–ค ์—ญํ• ์„ ํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ๊ณ ๋ฏผํ•˜์‹œ๊ณ  ์ฝ”๋“œ ์ž‘์„ฑํ•˜์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹น

@JacksonPk
Copy link

๊ถ๊ธˆํ–ˆ๋˜ ์ ์€ Persistence์— ์žˆ๋Š” ์ด ๋ฐ์ดํ„ฐ๋“ค์„ ๊ณ ์•ˆํ•œ ๋ฐฉ์‹์ฒ˜๋Ÿผ ๊ด€๋ฆฌํ•ด๋„ ๊ดœ์ฐฎ์€ ๊ฒƒ์ธ์ง€, ํ˜น์€ ๋” ๋‚˜์€๋ฐฉ๋ฒ•์ด๋‚˜ ๋‹ค๋ฅธ ์ ‘๊ทผ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค.

โ€‹=>๋„ต, ์ง€๊ธˆ๊ณผ ๊ฐ™์ด ์ž‘์„ฑํ•ด๋„ ๊ดœ์ฐฎ์„ ๊ฒƒ ๊ฐ™๋„ค์š”! primaryKey๋„ ์ž˜์“ฐ๊ณ  ๊ณ„์‹œ๊ณ ์š”. ์ด ํ”„๋กœ์ ํŠธ ๋ง๊ณ  ๋” ๋ณต์žกํ•œ ์ƒํ™ฉ์ด ์žˆ์–ด์•ผ ๋” ๋‚˜์€ ๋ฐฉ๋ฒ•์ด ๋ญ๊ฐ€ ์žˆ์„์ง€ ๊ณ ๋ฏผํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ๋ฐฑ์—”๋“œ๋ถ„๋“ค์—๊ฒŒ DB ์ž‘์„ฑํ•˜๊ธฐ ๊นŒ๋‹ค๋กœ์šด ์ƒํ™ฉ์œผ๋กœ ์–ด๋–ค๊ฒŒ ์žˆ๋Š”์ง€ ์งˆ๋ฌธํ•ด๋ณด์„ธ์š” ใ…Žใ…Ž
=> ๋‹ค๋งŒ ์‚ฌ์šฉํ•˜๋Š” ์ „์ฒด์ ์ธ ๋กœ์ง์ด ํšจ์œจ์ ์ด์ง€ ๋ชปํ•œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๋ชจ๋ฐ”์ผ์—์„œ DB๋Š” ๋„คํŠธ์›Œํฌ ์‚ฌ์šฉ๋Ÿ‰์„ ์ค„์ด๊ธฐ ์œ„ํ•ด์„œ๋„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋งจ ์ฒ˜์Œ์—๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ๋ฐ›์•„ DB์— ์ €์žฅํ•˜๊ณ , ๊ทธ ์ดํ›„์—๋Š” DB์— ๋ฐ์ดํ„ฐ๊ฐ€ ์žˆ๋‹ค๋ฉด ๋ฐ์ดํ„ฐ๋ฅผ ์„œ๋ฒ„๋กœ ์š”์ฒญํ•˜์ง€ ์•Š๊ณ  DB์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์–ด๋–จ๊นŒ์š”? ๊ทธ๋ฆฌ๊ณ  ์—…๋ฐ์ดํŠธ Interval๋ฅผ ๋‘ฌ์„œ ์‹œ๊ฐ„์ด ์ง€๋‚˜ ๋ฐ์ดํ„ฐ๋ฅผ ์—…๋ฐ์ดํŠธ ํ•ด์•ผ ํ•˜๋ฉด ๋‹ค์‹œ ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ๋ฐ์ดํ„ฐ๋ฅผ ์š”์ฒญํ•˜๋Š”๊ฑฐ์ฃ .

๋„ค, ๊ทธ ๋กœ์ง์ด ์ข‹์€ ๋ฐฉ์‹์ด๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. ์ œ๊ฐ€ ๊ณ„์† ์ƒ๊ฐํ•ด๋ดค๋˜ ๊ฒƒ์ด ์‹ค์ œ ์•ฑ์ด๋ผ๊ณ  ์ƒ๊ฐํ•ด๋ดค์„ ๋•Œ, ์„œ๋ฒ„์—์„œ ์—…๋ฐ์ดํŠธ ๋˜์ง€ ์•Š์•˜์„๊นŒ(์˜ˆ๋ฅผ๋“ค์–ด, ํŠน์ • ๊ฐ€๊ฒŒ์—์„œ ๋ฉ”๋‰ด์˜ ๊ฐ€๊ฒฉ์„ ๋ฐ”๊พผ๋‹ค๋˜์ง€.) DB์— ์žˆ๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด์—ฌ์ฃผ๋ฉด ์‚ฌ์šฉ์ž์ธก๋ฉด์—์„œ ํ˜ผ๋ˆ์ด ์˜ฌ๊นŒ ์‹ถ์–ด์„œ ๋„คํŠธ์›Œํฌ๊ฐ€ ์—ฐ๊ฒฐ์ด ๋˜์ง€ ์•Š์„ ๊ฒฝ์šฐ์—๋งŒ ์ผ์‹œ์ ์œผ๋กœ DB์— ์žˆ๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด์—ฌ์ฃผ๋„๋ก ๋กœ์ง์„ ์งœ ๋ณด์•˜์Šต๋‹ˆ๋‹ค. ์—…๋ฐ์ดํŠธ Interval์— ๋Œ€ํ•œ ๊ฐœ๋…์„ ์ดํ•ดํ•˜์ง€๋ชปํ•ด์„œ ์ด๋ ‡๊ฒŒ ๋กœ์ง์„ ๊ตฌํ˜„ํ–ˆ๋„ค์š”. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

@ehgud0670
Copy link

๋„ต, ์ถ”๊ฐ€๋กœ time interval์— ๋Œ€ํ•ด์„œ๋„ ๋ง์”€๋“œ๋ฆฌ๊ณ ์ž ์ฝ”๋ฉ˜ํŠธ ๋“œ๋ ธ์–ด์š”, ์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค! ๐Ÿ‘

itemsแ„€แ…ก แ„†แ…ฅแ†ซแ„Œแ…ฅ แ„‹แ…ฅแ†ธแ„ƒแ…ฆแ„‹แ…ตแ„แ…ณแ„ƒแ…ฌแ†ซ แ„ƒแ…กแ„‹แ…ณแ†ท categoryแ„‹แ…ฆ แ„‰แ…ฉแ†จแ„’แ…กแ†ซ itemsแ„€แ…ก แ„‹แ…ฅแ†ธแ„ƒแ…ฆแ„‹แ…ตแ„แ…ณ แ„ƒแ…ฌแ„ƒแ…ฉแ„…แ…ฉแ†จ แ„‰แ…ฎแ†ซแ„‰แ…ฅแ„…แ…ณแ†ฏ แ„Œแ…ฉแ„Œแ…ฅแ†ผ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review-iOS iOS ๋ฆฌ๋ทฐ
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants