Skip to content

Commit

Permalink
Feat: Section 3.4. Update
Browse files Browse the repository at this point in the history
### Motivation
- Section 4 Use an Observable Object for Storage

### Key Changes
- Section 4 Use an Observable Object for Storage 예제 코드 및 주석 추가

### To Reviewers
- 없음
  • Loading branch information
garlicvread committed Aug 11, 2022
1 parent 3a39361 commit 7f893b4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Binary file not shown.
13 changes: 10 additions & 3 deletions tutorial/Model/ModelData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@
//

import Foundation

// 2.1.10 landmarkData.json의 데이터를 받아올 어레이 선언
var landmarks: [Landmark] = load("landmarkData.json")
import Combine // 3.4.2. ObservableObject 사용을 위해 컴바인 라이브러리 호출

// 3.4.2. 새 model 타입 정의: ObservableObject -> 데이터 저장/연동
// ObservableObject의 값이 변하면 SwiftUI에서 새로 렌더링을 해 준다.
final class ModelData: ObservableObject {
// 2.1.10 landmarkData.json의 데이터를 받아올 어레이 선언
// 3.4.3. Landmark 배열을 ModelData 클래스 내로 이동
// 3.4.4. landmarks 변수에 @Published 속성 추가 -> SwiftUI 가 값 변동을 알 수 있도록 해 줌
@Published var landmarks: [Landmark] = load("landmarkData.json")
}

// 2.1.9. 애플리케이션의 메인 번들에서 지정된 이름의 json 데이터를 가져오는 메서드 생성
// load 메서드는 Codable 프로토콜의 구성요소인 Decodable 프로토콜의 반환 타입을 따른다.
Expand Down

0 comments on commit 7f893b4

Please sign in to comment.