Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Storage.swift
- // Cashbox
- //
- // Created by Konstanty on 27.07.17.
- // Copyright © 2017 Konstanty. All rights reserved.
- //
- import Foundation
- class Storage {
- static let instance = Storage() //singleton
- private var products = [Product]()
- //Проверка наличия
- class func isProductAvailable(productID: String) -> Bool {
- for product in instance.products {
- if product.productID == productID {
- return true
- }
- }
- return false
- }
- func addProduct(product: Product) {
- products.append(product)
- }
- func returnProduct(productID: String) {
- products.append(productID)
- }
- func removeProduct(productID: String) {
- for i in 0 ..< products.count {
- if products[i].productID == productID {
- products.remove(at: i)
- break
- }
- }
- }
- class func productById(productID: String) -> Product? {
- for product in instance.products {
- if product.productID == productID {
- return product
- }
- }
- return nil
- }
- // class func returnProduct(productID: String) {
- // for product in instance.products {
- // if product.productID == productID {
- // Product.price += Customer.moneyInWallet
- //
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement