Skip to content

Commit

Permalink
#18 lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Yerin Hwang committed Aug 17, 2017
1 parent bf3d800 commit a877e5a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 67 deletions.
42 changes: 21 additions & 21 deletions Product.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
import Foundation

class Product {

private let pid: Int //상품 아이디
private let mid: Int //재료 아이디(참조)
private let name: String
private let price: Decimal
private let weight: String
private var bundle: String
private let image: String

init() {
self.pid = 0
self.mid = 0
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -47,17 +47,17 @@ 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 {
return nil
}
mid = material_id
}

let decimalPrice = NSDecimalNumber.init(string: price.replacingOccurrences(of: ",", with: ""))

self.pid = pid
self.mid = mid
self.name = name
Expand All @@ -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
}
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
}
}
Expand Down
36 changes: 18 additions & 18 deletions ProductViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,47 @@ 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!
@IBAction func bundleStepperChanged(_ sender: Any) {
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) {
data.product.setBundle(input: bundleLabel.text ?? "1 개")
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 {
Expand All @@ -62,32 +62,32 @@ class ProductViewController: UIViewController {
secondViewController.editedProduct = product
}
}

func setBundleStepper() {
bundleStepper.minimumValue = 1
bundleStepper.maximumValue = 30
bundleStepper.stepValue = 1
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("")
Expand Down
56 changes: 28 additions & 28 deletions RecipeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -79,57 +79,57 @@ 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)
}
}
} 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)
}
Expand Down

0 comments on commit a877e5a

Please sign in to comment.