diff --git a/sources/ComicDetailsViewController.swift b/sources/ComicDetailsViewController.swift index 5ff6d2b..58bdd21 100644 --- a/sources/ComicDetailsViewController.swift +++ b/sources/ComicDetailsViewController.swift @@ -2,18 +2,17 @@ // Created: 2019-09-21 // - import UIKit class ComicDetailsViewController: UIViewController { - var comicId:Int? - var comicImage:UIImage? - var tags:[String]? + var comicId: Int? + var comicImage: UIImage? + var tags: [String]? - //Mark: UI Elements + // MARK: UI Elements let comicImageView: UIImageView = { - let imageView = UIImageView(frame: CGRect(x: 0,y: 0,width: 150,height: 150)) + let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 150, height: 150)) imageView.contentMode = UIView.ContentMode.scaleAspectFill imageView.clipsToBounds = true return imageView @@ -47,7 +46,7 @@ class ComicDetailsViewController: UIViewController { return addTagButton }() - //Mark: Methods + // MARK: Methods override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .white @@ -61,7 +60,7 @@ class ComicDetailsViewController: UIViewController { setupTagCollectionView() } - fileprivate static func createHorizontalRowStack() -> UIStackView{ + fileprivate static func createHorizontalRowStack() -> UIStackView { let horizontalStackView = UIStackView(frame: CGRect.zero) horizontalStackView.axis = .horizontal horizontalStackView.translatesAutoresizingMaskIntoConstraints = false @@ -74,7 +73,7 @@ class ComicDetailsViewController: UIViewController { fileprivate static func createColumnStack() -> UIStackView { let verticalStackView = UIStackView(frame: CGRect.zero) verticalStackView.axis = .vertical - verticalStackView.translatesAutoresizingMaskIntoConstraints = false; + verticalStackView.translatesAutoresizingMaskIntoConstraints = false return verticalStackView } @@ -107,8 +106,17 @@ class ComicDetailsViewController: UIViewController { } fileprivate func setupNavigationBar() { - navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(onCancel)) - navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(onSave)) + + navigationItem.leftBarButtonItem = + UIBarButtonItem(barButtonSystemItem: .cancel, + target: self, + action: #selector(onCancel)) + + navigationItem.rightBarButtonItem = + UIBarButtonItem(barButtonSystemItem: .save, + target: self, + action: #selector(onSave)) + navigationController?.navigationBar.isTranslucent = false } @@ -119,10 +127,10 @@ class ComicDetailsViewController: UIViewController { } fileprivate func loadTags() { - tags = ["Astronomy", "Discovery", "Futility", "Survival", "Scientist"].sorted() + tags = ["Astronomy", "Discovery", "Futility", "Survival", "Scientist"].sorted() } - //Mark: Navigation Actions + // MARK: Navigation Actions @objc func onSave() { //To do callback } @@ -138,9 +146,12 @@ extension ComicDetailsViewController: UICollectionViewDataSource { } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - guard let tagCell = collectionView.dequeueReusableCell(withReuseIdentifier: "TagCell", for: indexPath) as? TagCell else { - return UICollectionViewCell() - } + + let tagCell = collectionView + .dequeueReusableCell(withReuseIdentifier: "TagCell", + for: indexPath) + as! TagCell // swiftlint:disable:this force_cast + tagCell.textLabel.text = tags?[indexPath.row] return tagCell } @@ -151,10 +162,9 @@ extension ComicDetailsViewController: UICollectionViewDelegate { } - class TagCell: UICollectionViewCell { - var textLabel:UILabel = { + var textLabel: UILabel = { let label = UILabel() label.translatesAutoresizingMaskIntoConstraints = false label.font = UIFont.preferredFont(forTextStyle: .subheadline) diff --git a/sources/ComicViewController.swift b/sources/ComicViewController.swift index 21856c1..997f18b 100644 --- a/sources/ComicViewController.swift +++ b/sources/ComicViewController.swift @@ -51,9 +51,6 @@ class ComicViewController: UIViewController { } private func addConstraints() { - // TODO - Added by Arun - // commenting the next line because we are still loading this view fro the storyboard - // view.translatesAutoresizingMaskIntoConstraints = false comicImageView.translatesAutoresizingMaskIntoConstraints = false view.centerXAnchor.constraint(equalTo: comicImageView.centerXAnchor).isActive = true @@ -72,7 +69,6 @@ class ComicViewController: UIViewController { comicImageView.addGestureRecognizer(tapGestureRecognizer) } - // MARK: UTILITIES private func nextComic() { @@ -93,11 +89,10 @@ class ComicViewController: UIViewController { currentComic = previousComic } - private func showDetails() { let comicDetailsViewController = ComicDetailsViewController() comicDetailsViewController.comicId = currentComic?.id - comicDetailsViewController.comicImage = currentComic?.image + comicDetailsViewController.comicImage = comicImageView.image let navigationController = UINavigationController(rootViewController: comicDetailsViewController) present(navigationController, animated: false) } @@ -106,7 +101,6 @@ class ComicViewController: UIViewController { return Int.random(in: 0 ... 2198) } - // MARK: ACTIONS @objc func handleBackGesture(_ sender: UISwipeGestureRecognizer) {