jinios / swift-storeapp Goto Github PK
View Code? Open in Web Editor NEWThis project forked from code-squad/swift-storeapp
쇼핑몰 앱 - 코드스쿼드 미션 (2018.07 - 2018.08)
This project forked from code-squad/swift-storeapp
쇼핑몰 앱 - 코드스쿼드 미션 (2018.07 - 2018.08)
URLSession.shared.downloadTask(with: URL(string: url)!) { (tmpLocation, response, error) in
if let error = error {
print("Image download Error log: \(error)\n")
}
if let response = response as? HTTPURLResponse, response.statusCode == 200, let tmpLocation = tmpLocation {
do {
try fileManager.moveItem(at: tmpLocation, to: imageSavingPath)
if let imageData = try? Data(contentsOf: imageSavingPath) {
handler(imageData)
} else {
print("MOVE Error!")
}
} catch { print("MOVE Error!") }
}
}.resume()
}
}
3개의 JSON 데이터가 모두 받고 나면 JSON 데이터에 포함된 이미지 URL을 분리해서 Image 파일들을 다운로드 받는다.
이미지 파일들을 병렬처리해서 한꺼번에 여러개를 다운로드하도록 구성한다.
(선택1) GCD Queue를 활용하거나
(선택2)Download Task 방식으로 구현한다.
다운로드가 완료되면 앱 디렉토리 중에 Cache 디렉토리에 URL에 있는 파일명으로 저장한다.
셀을 표기할 때 이미 다운로드된 이미지가 있으면 표시하고, 새로운 파일이 다운로드 완료되면 해당 이미지를 테이블뷰 셀에 뒤늦게(lazy) 표시한다.
화면에 표시할 때 다운로드를 담당하는 스레드와 화면을 처리하는 스레드를 위한 GCD Queue를 구분해서 처리한다.
이미지를 다 받을때 까지 화면이 하얗게 멈춰있지 않도록 만든다.
상품상세정보를 표시하는 화면이아닌 네트워크에 연결되지 않았음
을 사용자에게 알릴 뷰 표시
setThumbnailScrollView() 나 setDetailScrollView() 에서 하는 작업은 결국 내부 뷰에 서브뷰를 추가하는 작업인데
이 부분을 ViewController에서 하지 않는다면 어떻게 분리할 수 있을까요?
Vertical ScrollView
url로부터 받은 이미지파일이 저장된 임시경로에서 cache에 지정한 경로로 옮겨지지 않는 에러 발생
상품 카테고리에 따라 다른 테이블뷰 헤더를 적용한다.
JSONDecoder를 활용해서 내부에 Array 타입으로 변환하는 DataSource에서 사용할 모델 객체를 만든다.
subscript로 배열에 index로 접근하면 StoreItem 구조체를 반환한다.
StoreItem은 Decodable 프로토콜을 채택하고, main.json에 있는 키와 값을 매핑해서 속성으로 갖도록 구현한다.
UITableViewDataSource 프로토콜 구현 부분에서 cell을 위에서 만든 DataSource 모델 객체에 접근해서 테이블뷰를 표시한다.
ImageSetter 클래스 함수로 분리하여 모델과 뷰를 담당하는 객체 역할 분리하기
// StoreItems.swift에서 전역변수로 사용
let CATEGORIES: [Category] = [.main, .soup, .side]
JK: 전역변수를 사용하기 보다는 StoreItems 같은 객체 네임스페이스를 활용해서 섹션에 대한 type 변수로 static 하게 설정해주는 게 어떨까요
해결:
테이블뷰에서 셀을 선택하면 선택한 셀의 hash data를 push되는 itemVC의 프로퍼티로 넘김
스토어앱 마지막단계 피드백 정리
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.