From a877e5a865fbcbe84805bd19d72a4d314a846940 Mon Sep 17 00:00:00 2001 From: Yerin Hwang Date: Thu, 17 Aug 2017 19:26:19 +0900 Subject: [PATCH] #18 lint --- Product.swift | 42 ++++++++++++++-------------- ProductViewController.swift | 36 ++++++++++++------------ RecipeViewController.swift | 56 ++++++++++++++++++------------------- 3 files changed, 67 insertions(+), 67 deletions(-) diff --git a/Product.swift b/Product.swift index 8110a08..80d8618 100644 --- a/Product.swift +++ b/Product.swift @@ -9,7 +9,7 @@ import Foundation class Product { - + private let pid: Int //상품 아이디 private let mid: Int //재료 아이디(참조) private let name: String @@ -17,7 +17,7 @@ class Product { private let weight: String private var bundle: String private let image: String - + init() { self.pid = 0 self.mid = 0 @@ -27,7 +27,7 @@ class Product { self.bundle = "" self.image = "" } - + init(pid: Int, mid: Int, name: String, price: Decimal, weight: String, bundle: String, image: String) { self.pid = pid self.mid = mid @@ -37,7 +37,7 @@ class Product { self.bundle = bundle self.image = image } - + init?(data: [String:Any]) { guard let pid = data["id"]! as? Int, let name = data["name"]! as? String, @@ -47,7 +47,7 @@ class Product { let image = data["image"]! as? String else { return nil } - + var mid = 0 if data["material_id"] != nil { guard let material_id = data["material_id"]! as? Int else { @@ -55,9 +55,9 @@ class Product { } mid = material_id } - + let decimalPrice = NSDecimalNumber.init(string: price.replacingOccurrences(of: ",", with: "")) - + self.pid = pid self.mid = mid self.name = name @@ -66,11 +66,11 @@ class Product { self.bundle = bundle self.image = image } - + func setBundle(input: String) { self.bundle = input } - + func getId() -> Int { return self.pid } @@ -96,16 +96,16 @@ class Product { return "http://" + self.image } } - + func getBundleTuple(input: String) -> (number: Int, unit: String) { var bundle = input var number = "" var unit = "" - + if input == "" { bundle = self.bundle } - + for character in bundle.characters { if Int.init(character.description) != nil { number.append(character) @@ -115,27 +115,27 @@ class Product { unit.append(character) } } - + guard let converted = Int.init(number) else { return (number: 1, unit: "개") } - + if unit == "" { unit = "개" } - + return (number: converted, unit: unit) } - + func getBundleString(input: String) -> String { var bundle = input var number = "" var unit = "" - + if input == "" { bundle = self.bundle } - + for character in bundle.characters { if Int.init(character.description) != nil { number.append(character) @@ -145,15 +145,15 @@ class Product { unit.append(character) } } - + guard let converted = Int.init(number) else { return "1 개" } - + if unit == "" { unit = "개" } - + return converted.description.appending(" ").appending(unit) } } diff --git a/ProductViewController.swift b/ProductViewController.swift index 1a5a375..7781991 100644 --- a/ProductViewController.swift +++ b/ProductViewController.swift @@ -10,13 +10,13 @@ import AlamofireImage import UIKit class ProductViewController: UIViewController { - + @IBOutlet weak var productImage: UIImageView! @IBOutlet weak var titleLabel: UILabel! @IBOutlet weak var descriptionLabel: UILabel! - + @IBOutlet weak var priceLabel: UILabel! - + //bundle label and stepper @IBOutlet weak var bundleLabel: UILabel! @IBOutlet weak var bundleStepper: UIStepper! @@ -24,12 +24,12 @@ class ProductViewController: UIViewController { let value = Int.init(bundleStepper.value) let bundle = value.description.appending(bundleUnit) bundleLabel.text = data.product.getBundleString(input: bundle) - + calcTotalPrice() } - + @IBOutlet weak var totalPriceLabel: UILabel! - + //confirm button @IBOutlet weak var confirmButton: UIBarButtonItem! @IBAction func touchConfirmButton(_ sender: Any) { @@ -37,20 +37,20 @@ class ProductViewController: UIViewController { let edited = (product: data.product, number: Int.init(bundleStepper.value), on: true) self.performSegue(withIdentifier: "unwindToRecipe", sender: edited) } - + var data = (product: Product.init(), number: 0, on: false) var bundleUnit = "" - + override func viewDidLoad() { super.viewDidLoad() setBundleStepper() productInfo() } - + override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } - + override func prepare(for segue: UIStoryboardSegue, sender: Any!) { if segue.identifier == "unwindToRecipe" { guard let secondViewController = segue.destination as? RecipeViewController else { @@ -62,7 +62,7 @@ class ProductViewController: UIViewController { secondViewController.editedProduct = product } } - + func setBundleStepper() { bundleStepper.minimumValue = 1 bundleStepper.maximumValue = 30 @@ -70,24 +70,24 @@ class ProductViewController: UIViewController { bundleStepper.autorepeat = true bundleStepper.value = Double.init(data.product.getBundleTuple(input: "").number) } - + func productInfo() { let product = data.product - + productImage.af_setImage(withURL: URL(string: product.getImage())!) - + titleLabel.text = product.getName() descriptionLabel.text = "" - + priceLabel.text = product.getPrice().description.appending(" 원") - + bundleUnit = product.getBundleTuple(input: "").unit bundleLabel.text = product.getBundleString(input: "") bundleStepper.value = Double(product.getBundleTuple(input: "").number) - + calcTotalPrice() } - + func calcTotalPrice() { let result = Decimal.init(bundleStepper.value) * data.product.getPrice() totalPriceLabel.text = "총 ".appending(result.description).appending(" 원") diff --git a/RecipeViewController.swift b/RecipeViewController.swift index cd2848e..72f39af 100644 --- a/RecipeViewController.swift +++ b/RecipeViewController.swift @@ -11,60 +11,60 @@ import Alamofire import AlamofireImage class RecipeViewController: UIViewController { - + let network = Network.init() var searchUrl = "" var searchRecipe = Recipe.init() var editedProduct = (product: Product(), number: 0, on: true) - + private let priceModified = Notification.Name.init(rawValue: "PriceModified") - + @IBOutlet weak var recipeImage: UIImageView! @IBOutlet weak var recipeTitleLabel: UILabel! @IBOutlet weak var recipeSubTitleLabel: UILabel! @IBOutlet weak var recipeServeLabel: UILabel! @IBOutlet weak var recipeMissed: UILabel! - + @IBOutlet weak var totalPriceLabel: UILabel! @IBOutlet weak var productTable: UITableView! - + @IBAction func unwindToRecipe(segue: UIStoryboardSegue) { let index = searchRecipe.indexOf(product: editedProduct.product) searchRecipe.setNumber(index: index, number: editedProduct.number) - + self.productTable.reloadData() self.updatePrice() } - + override func viewDidLoad() { super.viewDidLoad() - + //swiftlint:disable line_length NotificationCenter.default.addObserver(self, selector: #selector(updatePrice), name: self.priceModified, object: nil) - + productTable.tableFooterView = UIView() - + drawRecipeDetail() } - + override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } - + func drawRecipeDetail() { recipeImage.af_setImage(withURL: URL(string: searchRecipe.image)!) recipeTitleLabel.text = searchRecipe.title recipeSubTitleLabel.text = searchRecipe.subtitle recipeServeLabel.text = searchRecipe.serving recipeMissed.text = searchRecipe.missed//.appending("은(는) 찾지 못했어요.") - + self.updatePrice() } - + func updatePrice() { totalPriceLabel.text = searchRecipe.totalPrice() } - + override func prepare(for segue: UIStoryboardSegue, sender: Any!) { if segue.identifier == "RecipeToProduct" { guard let secondViewController = segue.destination as? ProductViewController else { @@ -79,43 +79,43 @@ class RecipeViewController: UIViewController { } extension RecipeViewController: UITableViewDelegate, UITableViewDataSource { - + func numberOfSections(in tableView: UITableView) -> Int { return 1 } - + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return self.searchRecipe.products.count+1 //add row } - + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let row = indexPath.row let count = self.searchRecipe.products.count - + var identifier = "recipeAddCell" - + if row < count { identifier = "recipeCell" } - + guard let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath) as? RecipeTableViewCell else { return RecipeTableViewCell() } - + if row < count { let productCell = searchRecipe.products[indexPath.row] - + cell.checkboxHandler = { () -> Void in self.searchRecipe.toggleCheck(product: productCell.product) } - + cell.checkbox.on = productCell.on cell.productLabel.text = productCell.product.getName() let price = productCell.product.getPrice() * Decimal.init(productCell.product.getBundleTuple(input: "").number) cell.priceLabel.text = String(describing: price).appending(" 원") cell.eaLabel.text = productCell.product.getBundleString(input: "") - + cell.disclosureHandler = { () -> Void in if self.searchRecipe.products[indexPath.row].on { self.performSegue(withIdentifier: "RecipeToProduct", sender: productCell) @@ -123,13 +123,13 @@ extension RecipeViewController: UITableViewDelegate, UITableViewDataSource { } } else { cell.checkbox.isHidden = true - + let addButton = UIImageView.init(frame: CGRect(x: 10, y: 15, width: 20, height: 20)) addButton.image = UIImage.init(named: "logo.png") cell.addSubview(addButton) - + cell.productLabel.text = "추가하기" - + cell.disclosureHandler = { () -> Void in self.performSegue(withIdentifier: "RecipeToSearchProduct", sender: nil) }