2019년 1월 7일 월요일

App, WeatherToday

Sample Application for Practice


WeatherToday
(asset 출처: edwith, iOS 프로그래밍 부스트코스, Project 3)






JSON파일 데이터이용 (JSONDecoder, NSDataAsset)
do { self.weatherInfo = try jsonDecoder.decode([Weather].self, from: dataAsset.data)
       } catch {
           print(error.localizedDescription)
       }

prepare(for:sender:) Method로 다음 화면에 값전달
guard let nextViewController: ThirdViewController = segue.destination as? ThirdViewController else { return }

NumberFormatter를 이용하여 화씨온도에서 변환한 섭씨 온도 자릿수 지정
numberFormatter.maximumFractionDigits = 1

대체 행 색상 (Alternating Row Color)
if (indexPath.row % 2 == 0) {
           cell.backgroundColor = UIColor.lightGray.withAlphaComponent(0.1)
       } else {
           cell.backgroundColor = UIColor.white
       }

섭씨온도가 높은 순으로 셀 정렬
weatherInfo.sort() { $0.celsius > $1.celsius }

당겨서 새로고침 (UIRefreshControl)
refresh.addTarget(self, action: #selector(pullDownRefresh), for: .valueChanged)
self.firstTableView.addSubview(refresh)
refresh.attributedTitle = NSAttributedString(string: "Refreshing Data …”)