12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- //
- // FoodItem.swift
- // Comedores Sociales
- //
- // Created by Hector Carrion on 11/30/20.
- //
-
- import SwiftUI
-
- struct FoodItem: Identifiable {
- var id = UUID().uuidString
- // both Image And Name Are Same...
- var name: String
- var cuantity: String
- var priceLocal: Float
- var priceExternal: Float
- // Computed property
- var savings: Float {
- return (priceExternal - priceLocal).rounded(toPlaces: 2)
- }
- }
-
- var foods = [
-
- FoodItem(name: "Beans", cuantity: "15.5 Oz", priceLocal: 0.58, priceExternal: 0.79),
- FoodItem(name: "Carrots", cuantity: "1 Lb", priceLocal: 0.58, priceExternal: 0.99),
- FoodItem(name: "Crackers", cuantity: "7.6 Oz", priceLocal: 1.61, priceExternal: 2.29),
- FoodItem(name: "Eggs", cuantity: "1 Dozen", priceLocal: 1.11, priceExternal: 1.78),
- FoodItem(name: "Malanga", cuantity: "1 Lb", priceLocal: 0.84, priceExternal: 0.99),
- FoodItem(name: "Oatmeal", cuantity: "12 Oz", priceLocal: 1.67, priceExternal: 1.78),
- FoodItem(name: "Pasta", cuantity: "14 Oz", priceLocal: 0.56, priceExternal: 0.69),
- FoodItem(name: "Green Peppers", cuantity: "1 Lb", priceLocal: 1.72, priceExternal: 2.59),
- FoodItem(name: "Pineapple", cuantity: "1 Lb", priceLocal: 0.78, priceExternal: 0.99),
- FoodItem(name: "Potatoes", cuantity: "1 Lb", priceLocal: 0.49, priceExternal: 0.60),
- FoodItem(name: "Rice", cuantity: "3 Lb", priceLocal: 1, priceExternal: 1.25),
- FoodItem(name: "Sausages", cuantity: "4.6 Oz", priceLocal: 0.55, priceExternal: 0.69),
- FoodItem(name: "Vegetable Oil", cuantity: "16 Oz", priceLocal: 1.29, priceExternal: 1.78),
- FoodItem(name: "Yellow Onions", cuantity: "1 Lb", priceLocal: 0.58, priceExternal: 0.60),
- FoodItem(name: "Yuca", cuantity: "1 Lb", priceLocal: 0.62, priceExternal: 0.99)
- ]
-
-
- extension Float {
- /// Rounds the double to decimal places value
- func rounded(toPlaces places:Int) -> Float {
- let divisor = pow(10.0, Float(places))
- return (self * divisor).rounded() / divisor
- }
- }
|