Без опису

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // FoodItem.swift
  3. // Comedores Sociales
  4. //
  5. // Created by Hector Carrion on 11/30/20.
  6. //
  7. import SwiftUI
  8. struct FoodItem: Identifiable {
  9. var id = UUID().uuidString
  10. // both Image And Name Are Same...
  11. var name: String
  12. var cuantity: String
  13. var priceLocal: Float
  14. var priceExternal: Float
  15. // Computed property
  16. var savings: Float {
  17. return (priceExternal - priceLocal).rounded(toPlaces: 2)
  18. }
  19. }
  20. var foods = [
  21. FoodItem(name: "Beans", cuantity: "15.5 Oz", priceLocal: 0.58, priceExternal: 0.79),
  22. FoodItem(name: "Carrots", cuantity: "1 Lb", priceLocal: 0.58, priceExternal: 0.99),
  23. FoodItem(name: "Crackers", cuantity: "7.6 Oz", priceLocal: 1.61, priceExternal: 2.29),
  24. FoodItem(name: "Eggs", cuantity: "1 Dozen", priceLocal: 1.11, priceExternal: 1.78),
  25. FoodItem(name: "Malanga", cuantity: "1 Lb", priceLocal: 0.84, priceExternal: 0.99),
  26. FoodItem(name: "Oatmeal", cuantity: "12 Oz", priceLocal: 1.67, priceExternal: 1.78),
  27. FoodItem(name: "Pasta", cuantity: "14 Oz", priceLocal: 0.56, priceExternal: 0.69),
  28. FoodItem(name: "Green Peppers", cuantity: "1 Lb", priceLocal: 1.72, priceExternal: 2.59),
  29. FoodItem(name: "Pineapple", cuantity: "1 Lb", priceLocal: 0.78, priceExternal: 0.99),
  30. FoodItem(name: "Potatoes", cuantity: "1 Lb", priceLocal: 0.49, priceExternal: 0.60),
  31. FoodItem(name: "Rice", cuantity: "3 Lb", priceLocal: 1, priceExternal: 1.25),
  32. FoodItem(name: "Sausages", cuantity: "4.6 Oz", priceLocal: 0.55, priceExternal: 0.69),
  33. FoodItem(name: "Vegetable Oil", cuantity: "16 Oz", priceLocal: 1.29, priceExternal: 1.78),
  34. FoodItem(name: "Yellow Onions", cuantity: "1 Lb", priceLocal: 0.58, priceExternal: 0.60),
  35. FoodItem(name: "Yuca", cuantity: "1 Lb", priceLocal: 0.62, priceExternal: 0.99)
  36. ]
  37. extension Float {
  38. /// Rounds the double to decimal places value
  39. func rounded(toPlaces places:Int) -> Float {
  40. let divisor = pow(10.0, Float(places))
  41. return (self * divisor).rounded() / divisor
  42. }
  43. }