From c51351644dedb35e27e4aea9c2bc3e92f11a7b45 Mon Sep 17 00:00:00 2001 From: absdrenaline Date: Sun, 22 Sep 2019 20:01:52 -0700 Subject: [PATCH 1/2] Fixed the lint error/warnings --- sources/ComicDetailsViewController.swift | 44 +++++++++++++++--------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/sources/ComicDetailsViewController.swift b/sources/ComicDetailsViewController.swift index 623034f..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,7 +146,12 @@ extension ComicDetailsViewController: UICollectionViewDataSource { } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let tagCell = collectionView.dequeueReusableCell(withReuseIdentifier: "TagCell", for: indexPath) as! TagCell + + let tagCell = collectionView + .dequeueReusableCell(withReuseIdentifier: "TagCell", + for: indexPath) + as! TagCell // swiftlint:disable:this force_cast + tagCell.textLabel.text = tags?[indexPath.row] return tagCell } @@ -149,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) From 23e14720150254959ebed764424d02572c698188 Mon Sep 17 00:00:00 2001 From: absdrenaline Date: Sun, 22 Sep 2019 20:20:54 -0700 Subject: [PATCH 2/2] Pass the current comic image to detail view --- sources/ComicViewController.swift | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) 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) {