2019 Fall Interface Programming
for more information about MVC design pattern checkout iOS: Three ways to pass data from Model to Controller, Modern MVC and Lecture 2: MVC's by Stanford Univ.
Youtube API를 사용해 동영상 정보를 불러오는 Model입니다.
ViewController
와 소통하기 위한 protocol
func didUpdateVideos(_ youtubeManager: YoutubeManager, with video: YoutubeModel)
: video 정보 호출을 성공할 시, delegate은 해당 method를 부릅니다.func didFailWithError(error: Error)
: error가 날 시, delegate은 해당 method를 부릅니다.Delegate(YoutubeViewController
)은 이 method에 검색어를 parameter로 넘기고, 이 함수는 넘겨받은 검색어를 사용해 youtubeAPI에 사용할 url을 생성 후 이를 parameter로 YoutubeManager.performRequest()
를 호출합니다.
넘겨받은 url을 사용해 URLSession
과 URLSession.dataTask(with: url)
을 생성, data를 받아오는 함수입니다. 실패시 delegate method인 didFailWithError()
를 호출하고, 성공시에는 YoutubeManager.parseJSON(with: safeData)
를 호출합니다.
Foundation
라이브러리 내장함수인 JSONDecoder()
를 사용해 받아온 JSONdata를 parsing합니다.YoutubeModel
)에 집어넣는 함수입니다. YoutubeAPI가 제공하는 JSON data file에서 필요한 정보들을 찾기 위한 data type입니다. 변수명이 달라질 시, 정확한 정보를 담을 수 없습니다. YoutubeData.items[].snippet.thumnails.dafault
는 default
라는 swift 예약어를 사용하기 때문에, 백틱(`)을 사용해 변수명을 선언했습니다.
동영상 정보를 내부적으로 활용하기 위한 data 구조입니다.
가까운 매장을 custom Server API를 써 받아오는 모델
Custom Tableview를 구성하기 위한 Cell 입니다.
Used Libraries
Created by 백승호 on 2019/11/15. Edited by 백승호 on 2019/12/18. Copyright © 2019 Seungho Baek. All rights reserved.