From 3a8b8d187ba6ad86df207a18fd7b1a617634608a Mon Sep 17 00:00:00 2001 From: mohok Date: Sun, 20 Jan 2019 22:20:57 +0900 Subject: [PATCH 1/3] API Guide - lowerCamelCase --- MyBoxOffice/TableViewController.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MyBoxOffice/TableViewController.swift b/MyBoxOffice/TableViewController.swift index a13a3fa..569188f 100644 --- a/MyBoxOffice/TableViewController.swift +++ b/MyBoxOffice/TableViewController.swift @@ -94,7 +94,7 @@ class TableViewController: UIViewController, UITableViewDataSource, UITableViewD super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. - AddPullToRefresh() + addPullToRefresh() //Add Observer for movies data NotificationCenter.default.addObserver(self, selector: #selector(self.didRecieveMoviesNotification(_:)), name: DidReceiveMoviesNotification, object: nil) @@ -126,7 +126,7 @@ class TableViewController: UIViewController, UITableViewDataSource, UITableViewD } // MARK: - Refresh - func AddPullToRefresh() { + func addPullToRefresh() { if #available(iOS 10.0, *) { tableView.refreshControl = refreshControl } else { From 6f67de8717b935a499590f2d4135160e559ebb74 Mon Sep 17 00:00:00 2001 From: mohok Date: Sun, 20 Jan 2019 22:47:55 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E1=84=90=E1=85=A6=E1=84=8B=E1=85=B5?= =?UTF-8?q?=E1=84=87=E1=85=B3=E1=86=AF.=20=E1=84=90=E1=85=A2=E1=86=B8=20VC?= =?UTF-8?q?=20=E1=84=80=E1=85=A9=E1=86=BC=E1=84=90=E1=85=A9=E1=86=BC=20?= =?UTF-8?q?=E1=84=8F=E1=85=A9=E1=84=83=E1=85=B3=20=E1=84=87=E1=85=AE?= =?UTF-8?q?=E1=86=AB=E1=84=85=E1=85=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MyBoxOffice.xcodeproj/project.pbxproj | 4 + MyBoxOffice/CollectionViewController.swift | 86 +-------------------- MyBoxOffice/Extension.swift | 70 +++++++++++++++++ MyBoxOffice/Request.swift | 3 + MyBoxOffice/TableViewController.swift | 88 +--------------------- 5 files changed, 82 insertions(+), 169 deletions(-) create mode 100644 MyBoxOffice/Extension.swift diff --git a/MyBoxOffice.xcodeproj/project.pbxproj b/MyBoxOffice.xcodeproj/project.pbxproj index 41d0585..6c40427 100644 --- a/MyBoxOffice.xcodeproj/project.pbxproj +++ b/MyBoxOffice.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + E92D950A21F4B07C00FB386B /* Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = E92D950921F4B07C00FB386B /* Extension.swift */; }; EC352FCA21BD0D1100433AAD /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC352FC921BD0D1100433AAD /* AppDelegate.swift */; }; EC352FCC21BD0D1100433AAD /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC352FCB21BD0D1100433AAD /* TableViewController.swift */; }; EC352FCF21BD0D1100433AAD /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EC352FCD21BD0D1100433AAD /* Main.storyboard */; }; @@ -22,6 +23,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + E92D950921F4B07C00FB386B /* Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extension.swift; sourceTree = ""; }; EC352FC621BD0D1100433AAD /* MyBoxOffice.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MyBoxOffice.app; sourceTree = BUILT_PRODUCTS_DIR; }; EC352FC921BD0D1100433AAD /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; EC352FCB21BD0D1100433AAD /* TableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = ""; }; @@ -81,6 +83,7 @@ EC352FDB21BD100400433AAD /* CollectionViewController.swift */, EC352FD021BD0D1100433AAD /* Assets.xcassets */, EC352FD521BD0D1100433AAD /* Info.plist */, + E92D950921F4B07C00FB386B /* Extension.swift */, ); path = MyBoxOffice; sourceTree = ""; @@ -160,6 +163,7 @@ EC352FCC21BD0D1100433AAD /* TableViewController.swift in Sources */, EC352FE021BD1F3E00433AAD /* Request.swift in Sources */, ECFBFF6C21C0CE0200B6CD11 /* MoviesCollectionViewCell.swift in Sources */, + E92D950A21F4B07C00FB386B /* Extension.swift in Sources */, ECFC304721C6169B006E8586 /* OrderType.swift in Sources */, EC352FE221BD1F4B00433AAD /* Model.swift in Sources */, EC352FDE21BD105000433AAD /* InfoViewController.swift in Sources */, diff --git a/MyBoxOffice/CollectionViewController.swift b/MyBoxOffice/CollectionViewController.swift index 4574d66..ba478b9 100644 --- a/MyBoxOffice/CollectionViewController.swift +++ b/MyBoxOffice/CollectionViewController.swift @@ -94,12 +94,7 @@ class CollectionViewController: UIViewController, UICollectionViewDataSource, UI NotificationCenter.default.addObserver(self, selector: #selector(self.didRecieveMovieNotification(_:)), name: DidReceiveMoviesNotification, object: nil) - requestMovies(){ - (error) in - if let error = error { - self.AlertFailMessage(errorMessage: error.localizedDescription) - } - } + requestMoviesWithEscaping() } @objc func didRecieveMovieNotification(_ noti: Notification) { @@ -148,88 +143,11 @@ class CollectionViewController: UIViewController, UICollectionViewDataSource, UI } @objc func refresh() { - requestMovies(){ - (error) in - if let error = error { - self.AlertFailMessage(errorMessage: error.localizedDescription) - } - } + requestMoviesWithEscaping() self.collectionView.reloadData() self.refreshControl.endRefreshing() } - // MARK: - Action sheet - func showActionSheetController() { - let actionSheetController: UIAlertController - actionSheetController = UIAlertController(title: "정렬방식 선택", message: "영화를 어떤 순서로 정렬할까요?", preferredStyle: UIAlertControllerStyle.actionSheet) - - let reservationRateAction: UIAlertAction - reservationRateAction = UIAlertAction(title: "예매율", style: UIAlertActionStyle.default, handler: { (action: UIAlertAction) in - OrderType.orderTypeProperty = 0 - requestMovies(){ - (error) in - if let error = error { - self.AlertFailMessage(errorMessage: error.localizedDescription) - } - } - }) - - let curationAction: UIAlertAction - curationAction = UIAlertAction(title: "큐레이션", style: UIAlertActionStyle.default, handler: { (action: UIAlertAction) in - OrderType.orderTypeProperty = 1 - requestMovies(){ - (error) in - if let error = error { - self.AlertFailMessage(errorMessage: error.localizedDescription) - } - } - }) - - let releaseDateAction: UIAlertAction - releaseDateAction = UIAlertAction(title: "개봉일", style: UIAlertActionStyle.default, handler: { (action: UIAlertAction) in - OrderType.orderTypeProperty = 2 - requestMovies(){ - (error) in - if let error = error { - self.AlertFailMessage(errorMessage: error.localizedDescription) - } - } - }) - - let cancelAction: UIAlertAction - cancelAction = UIAlertAction(title: "취소", style: UIAlertActionStyle.cancel, handler: nil) - - actionSheetController.addAction(reservationRateAction) - actionSheetController.addAction(curationAction) - actionSheetController.addAction(releaseDateAction) - actionSheetController.addAction(cancelAction) - - if UIDevice.current.userInterfaceIdiom == .pad { - if let popoverController = actionSheetController.popoverPresentationController { - popoverController.sourceView = self.view - popoverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0) - popoverController.permittedArrowDirections = [] - self.present(actionSheetController, animated: true, completion: nil) - } - } - else { - self.present(actionSheetController, animated: true, completion: nil) - } - } - - //Alert `errorMessage` in `viewController`. - func AlertFailMessage(errorMessage: String) { - let actionSheetController: UIAlertController - actionSheetController = UIAlertController(title: "ERROR!", message: errorMessage, preferredStyle: UIAlertControllerStyle.alert) - - let cancelAction: UIAlertAction - cancelAction = UIAlertAction(title: "닫기", style: UIAlertActionStyle.cancel, handler: nil) - - actionSheetController.addAction(cancelAction) - - self.present(actionSheetController, animated: true, completion: nil) - } - // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation diff --git a/MyBoxOffice/Extension.swift b/MyBoxOffice/Extension.swift new file mode 100644 index 0000000..b8b6c82 --- /dev/null +++ b/MyBoxOffice/Extension.swift @@ -0,0 +1,70 @@ +// +// Extension.swift +// MyBoxOffice +// +// Created by 정화 on 20/01/2019. +// Copyright © 2019 Wongeun Song. All rights reserved. +// + +import UIKit + +extension UIViewController { + func requestMoviesWithEscaping() { + requestMovies(){ + (error) in + if let error = error { + self.alertFailMessage(errorMessage: error.localizedDescription) + } + } + } + + //Alert `errorMessage` in `viewController`. + func alertFailMessage(errorMessage: String) { + let actionSheetController = UIAlertController(title: "ERROR!", message: errorMessage, preferredStyle: .alert) + let cancelAction = UIAlertAction(title: "닫기", style: .cancel, handler: nil) + actionSheetController.addAction(cancelAction) + self.present(actionSheetController, animated: true, completion: nil) + } + + // MARK: - Action sheet + func showActionSheetController() { + let actionSheetController = UIAlertController(title: "정렬방식 선택", message: "영화를 어떤 순서로 정렬할까요?", preferredStyle: UIAlertControllerStyle.actionSheet) + + let reservationRateAction = UIAlertAction(title: "예매율", style: .default, handler: { (action: UIAlertAction) in + OrderType.orderTypeProperty = 0 + self.requestMoviesWithEscaping() + }) + + let curationAction = UIAlertAction(title: "큐레이션", style: .default, handler: { (action: UIAlertAction) in + OrderType.orderTypeProperty = 1 + self.requestMoviesWithEscaping() + + }) + + let releaseDateAction = UIAlertAction(title: "개봉일", style: .default, handler: { (action: UIAlertAction) in + OrderType.orderTypeProperty = 2 + self.requestMoviesWithEscaping() + }) + + let cancelAction = UIAlertAction(title: "취소", style: .cancel, handler: nil) + + actionSheetController.addAction(reservationRateAction) + actionSheetController.addAction(curationAction) + actionSheetController.addAction(releaseDateAction) + actionSheetController.addAction(cancelAction) + + if UIDevice.current.userInterfaceIdiom == .pad { + if let popoverController = actionSheetController.popoverPresentationController { + popoverController.sourceView = self.view + popoverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0) + popoverController.permittedArrowDirections = [] + self.present(actionSheetController, animated: true, completion: nil) + } + } + else { + self.present(actionSheetController, animated: true, completion: nil) + } + } + + +} diff --git a/MyBoxOffice/Request.swift b/MyBoxOffice/Request.swift index d732053..86f1fab 100644 --- a/MyBoxOffice/Request.swift +++ b/MyBoxOffice/Request.swift @@ -131,3 +131,6 @@ func requestMovieComments(id: String, completion: @escaping(_ error: Error?) -> dataTask.resume() } + + + diff --git a/MyBoxOffice/TableViewController.swift b/MyBoxOffice/TableViewController.swift index 569188f..685cb4e 100644 --- a/MyBoxOffice/TableViewController.swift +++ b/MyBoxOffice/TableViewController.swift @@ -99,12 +99,8 @@ class TableViewController: UIViewController, UITableViewDataSource, UITableViewD //Add Observer for movies data NotificationCenter.default.addObserver(self, selector: #selector(self.didRecieveMoviesNotification(_:)), name: DidReceiveMoviesNotification, object: nil) - requestMovies(){ - (error) in - if let error = error { - self.AlertFailMessage(errorMessage: error.localizedDescription) - } - } + self.requestMoviesWithEscaping() + } @objc func didRecieveMoviesNotification(_ noti: Notification) { @@ -132,93 +128,15 @@ class TableViewController: UIViewController, UITableViewDataSource, UITableViewD } else { tableView.addSubview(refreshControl) } - self.refreshControl.addTarget(self, action: #selector(refresh), for: .valueChanged) } @objc func refresh() { - requestMovies(){ - (error) in - if let error = error { - self.AlertFailMessage(errorMessage: error.localizedDescription) - } - } + self.requestMoviesWithEscaping() self.tableView.reloadData() self.refreshControl.endRefreshing() } - // MARK: - Action sheet - func showActionSheetController() { - let actionSheetController: UIAlertController - actionSheetController = UIAlertController(title: "정렬방식 선택", message: "영화를 어떤 순서로 정렬할까요?", preferredStyle: UIAlertControllerStyle.actionSheet) - - let reservationRateAction: UIAlertAction - reservationRateAction = UIAlertAction(title: "예매율", style: UIAlertActionStyle.default, handler: { (action: UIAlertAction) in - OrderType.orderTypeProperty = 0 - requestMovies(){ - (error) in - if let error = error { - self.AlertFailMessage(errorMessage: error.localizedDescription) - } - } - }) - - let curationAction: UIAlertAction - curationAction = UIAlertAction(title: "큐레이션", style: UIAlertActionStyle.default, handler: { (action: UIAlertAction) in - OrderType.orderTypeProperty = 1 - requestMovies(){ - (error) in - if let error = error { - self.AlertFailMessage(errorMessage: error.localizedDescription) - } - } - }) - - let releaseDateAction: UIAlertAction - releaseDateAction = UIAlertAction(title: "개봉일", style: UIAlertActionStyle.default, handler: { (action: UIAlertAction) in - OrderType.orderTypeProperty = 2 - requestMovies(){ - (error) in - if let error = error { - self.AlertFailMessage(errorMessage: error.localizedDescription) - } - } - }) - - let cancelAction: UIAlertAction - cancelAction = UIAlertAction(title: "취소", style: UIAlertActionStyle.cancel, handler: nil) - - actionSheetController.addAction(reservationRateAction) - actionSheetController.addAction(curationAction) - actionSheetController.addAction(releaseDateAction) - actionSheetController.addAction(cancelAction) - - if UIDevice.current.userInterfaceIdiom == .pad { - if let popoverController = actionSheetController.popoverPresentationController { - popoverController.sourceView = self.view - popoverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0) - popoverController.permittedArrowDirections = [] - self.present(actionSheetController, animated: true, completion: nil) - } - } - else { - self.present(actionSheetController, animated: true, completion: nil) - } - } - - //Alert `errorMessage` in `viewController`. - func AlertFailMessage(errorMessage: String) { - let actionSheetController: UIAlertController - actionSheetController = UIAlertController(title: "ERROR!", message: errorMessage, preferredStyle: UIAlertControllerStyle.alert) - - let cancelAction: UIAlertAction - cancelAction = UIAlertAction(title: "닫기", style: UIAlertActionStyle.cancel, handler: nil) - - actionSheetController.addAction(cancelAction) - - self.present(actionSheetController, animated: true, completion: nil) - } - // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation From d8dab92775bb0b8f842a3abb6cf73399c0a6d658 Mon Sep 17 00:00:00 2001 From: mohok Date: Sun, 20 Jan 2019 23:01:15 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E1=84=89=E1=85=A6=E1=86=AF=20=E1=84=8C?= =?UTF-8?q?=E1=85=A2=E1=84=89=E1=85=A1=E1=84=8B=E1=85=AD=E1=86=BC=20?= =?UTF-8?q?=E1=84=86=E1=85=AE=E1=86=AB=E1=84=8C=E1=85=A6=20-=20=E1=84=92?= =?UTF-8?q?=E1=85=AA=E1=84=86=E1=85=A7=E1=86=AB=E1=84=8B=E1=85=B3=E1=86=AF?= =?UTF-8?q?=20=E1=84=8B=E1=85=B1=E1=84=8B=E1=85=A1=E1=84=85=E1=85=A2?= =?UTF-8?q?=E1=84=85=E1=85=A9=20=E1=84=88=E1=85=A1=E1=84=85=E1=85=B3?= =?UTF-8?q?=E1=84=80=E1=85=A6=20=E1=84=8B=E1=85=AA=E1=86=BB=E1=84=83?= =?UTF-8?q?=E1=85=A1=E1=84=80=E1=85=A1=E1=86=BB=E1=84=83=E1=85=A1=E1=84=92?= =?UTF-8?q?=E1=85=A1=E1=84=86=E1=85=A7=E1=86=AB=20=E1=84=89=E1=85=A6?= =?UTF-8?q?=E1=86=AF=E1=84=8B=E1=85=B5=20=E1=84=8C=E1=85=A2=E1=84=89?= =?UTF-8?q?=E1=85=A1=E1=84=8B=E1=85=AD=E1=86=BC=E1=84=83=E1=85=AC=E1=84=86?= =?UTF-8?q?=E1=85=A7=E1=86=AB=E1=84=89=E1=85=A5=20=E1=84=8B=E1=85=B5?= =?UTF-8?q?=E1=86=AB=E1=84=83=E1=85=A6=E1=86=A8=E1=84=89=E1=85=B3=E1=84=8B?= =?UTF-8?q?=E1=85=A6=20=E1=84=86=E1=85=A1=E1=86=BD=E1=84=8C=E1=85=B5=20?= =?UTF-8?q?=E1=84=8B=E1=85=A1=E1=86=AD=E1=84=82=E1=85=B3=E1=86=AB=20?= =?UTF-8?q?=E1=84=80=E1=85=A1=E1=86=B9=E1=84=8B=E1=85=B5=20=E1=84=83?= =?UTF-8?q?=E1=85=B3=E1=86=AF=E1=84=8B=E1=85=A5=E1=84=80=E1=85=A1=E1=84=80?= =?UTF-8?q?=E1=85=A6=20=E1=84=83=E1=85=AC=E1=86=B7.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MyBoxOffice/MoviesTableViewCell.swift | 7 +++++++ MyBoxOffice/TableViewController.swift | 1 + 2 files changed, 8 insertions(+) diff --git a/MyBoxOffice/MoviesTableViewCell.swift b/MyBoxOffice/MoviesTableViewCell.swift index 30b0282..80e68cb 100644 --- a/MyBoxOffice/MoviesTableViewCell.swift +++ b/MyBoxOffice/MoviesTableViewCell.swift @@ -18,4 +18,11 @@ class MoviesTableViewCell: UITableViewCell { var movieId: String? + override func prepareForReuse() { + titleLabel.text = nil + infoLabel.text = nil + dateLabel.text = nil + thumbImageView.image = nil + gradeImageView.image = nil + } } diff --git a/MyBoxOffice/TableViewController.swift b/MyBoxOffice/TableViewController.swift index 685cb4e..8be0c77 100644 --- a/MyBoxOffice/TableViewController.swift +++ b/MyBoxOffice/TableViewController.swift @@ -28,6 +28,7 @@ class TableViewController: UIViewController, UITableViewDataSource, UITableViewD return movies.count } + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell: MoviesTableViewCell = tableView.dequeueReusableCell(withIdentifier: self.movieCellIdentifier, for: indexPath) as? MoviesTableViewCell ?? MoviesTableViewCell()