From d08017692a08eedffc9feda05adc34571a0408bd Mon Sep 17 00:00:00 2001 From: dmills14 Date: Fri, 22 May 2020 08:47:22 -0700 Subject: [PATCH 1/3] initial set up --- Shopping List.xcodeproj/project.pbxproj | 20 ++-- Shopping List/Base.lproj/Main.storyboard | 82 +++++++++++++++-- Shopping List/FileManager.swift | 47 ++++++++++ Shopping List/ShoppingItem.swift | 19 ++++ ...ShoppingListCollectionViewController.swift | 91 +++++++++++++++++++ Shopping List/ViewController.swift | 25 ----- .../{Info.plist => shoppingList.plist} | 0 7 files changed, 244 insertions(+), 40 deletions(-) create mode 100644 Shopping List/FileManager.swift create mode 100644 Shopping List/ShoppingItem.swift create mode 100644 Shopping List/ShoppingListCollectionViewController.swift delete mode 100644 Shopping List/ViewController.swift rename Shopping List/{Info.plist => shoppingList.plist} (100%) diff --git a/Shopping List.xcodeproj/project.pbxproj b/Shopping List.xcodeproj/project.pbxproj index 9970ba97..ec6fd424 100644 --- a/Shopping List.xcodeproj/project.pbxproj +++ b/Shopping List.xcodeproj/project.pbxproj @@ -8,20 +8,24 @@ /* Begin PBXBuildFile section */ 4613E91221143BFC00E7FF73 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4613E91121143BFC00E7FF73 /* AppDelegate.swift */; }; - 4613E91421143BFC00E7FF73 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4613E91321143BFC00E7FF73 /* ViewController.swift */; }; 4613E91721143BFC00E7FF73 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4613E91521143BFC00E7FF73 /* Main.storyboard */; }; 4613E91921143BFD00E7FF73 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4613E91821143BFD00E7FF73 /* Assets.xcassets */; }; 4613E91C21143BFD00E7FF73 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4613E91A21143BFD00E7FF73 /* LaunchScreen.storyboard */; }; + 56F7A4CF247821C9006FBE7F /* ShoppingItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F7A4CE247821C9006FBE7F /* ShoppingItem.swift */; }; + 56F7A4D1247827A2006FBE7F /* ShoppingListCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F7A4D0247827A2006FBE7F /* ShoppingListCollectionViewController.swift */; }; + 56F7A4D5247828DB006FBE7F /* FileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F7A4D4247828DB006FBE7F /* FileManager.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ 4613E90E21143BFC00E7FF73 /* Shopping List.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Shopping List.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 4613E91121143BFC00E7FF73 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; - 4613E91321143BFC00E7FF73 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 4613E91621143BFC00E7FF73 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 4613E91821143BFD00E7FF73 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 4613E91B21143BFD00E7FF73 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; - 4613E91D21143BFD00E7FF73 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 4613E91D21143BFD00E7FF73 /* shoppingList.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = shoppingList.plist; sourceTree = ""; }; + 56F7A4CE247821C9006FBE7F /* ShoppingItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoppingItem.swift; sourceTree = ""; }; + 56F7A4D0247827A2006FBE7F /* ShoppingListCollectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoppingListCollectionViewController.swift; sourceTree = ""; }; + 56F7A4D4247828DB006FBE7F /* FileManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileManager.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -54,12 +58,14 @@ 4613E91021143BFC00E7FF73 /* Shopping List */ = { isa = PBXGroup; children = ( + 56F7A4CE247821C9006FBE7F /* ShoppingItem.swift */, 4613E91121143BFC00E7FF73 /* AppDelegate.swift */, - 4613E91321143BFC00E7FF73 /* ViewController.swift */, 4613E91521143BFC00E7FF73 /* Main.storyboard */, + 56F7A4D0247827A2006FBE7F /* ShoppingListCollectionViewController.swift */, + 56F7A4D4247828DB006FBE7F /* FileManager.swift */, 4613E91821143BFD00E7FF73 /* Assets.xcassets */, 4613E91A21143BFD00E7FF73 /* LaunchScreen.storyboard */, - 4613E91D21143BFD00E7FF73 /* Info.plist */, + 4613E91D21143BFD00E7FF73 /* shoppingList.plist */, ); path = "Shopping List"; sourceTree = ""; @@ -135,8 +141,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 4613E91421143BFC00E7FF73 /* ViewController.swift in Sources */, + 56F7A4CF247821C9006FBE7F /* ShoppingItem.swift in Sources */, + 56F7A4D1247827A2006FBE7F /* ShoppingListCollectionViewController.swift in Sources */, 4613E91221143BFC00E7FF73 /* AppDelegate.swift in Sources */, + 56F7A4D5247828DB006FBE7F /* FileManager.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Shopping List/Base.lproj/Main.storyboard b/Shopping List/Base.lproj/Main.storyboard index 03c13c22..468a77fa 100644 --- a/Shopping List/Base.lproj/Main.storyboard +++ b/Shopping List/Base.lproj/Main.storyboard @@ -1,24 +1,88 @@ - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - + + + - - + + + - + + + + + + + + + + + + + + + + + + + + diff --git a/Shopping List/FileManager.swift b/Shopping List/FileManager.swift new file mode 100644 index 00000000..cce8c8e1 --- /dev/null +++ b/Shopping List/FileManager.swift @@ -0,0 +1,47 @@ +// +// FileManager.swift +// Shopping List +// +// Created by Drew Miller on 5/22/20. +// Copyright © 2020 Lambda School. All rights reserved. +// + +import Foundation + +var shopping: [ShoppingItem] = [] + +var shoppingListURL: URL? { + + let fileManager = FileManager.default + + let documentsDir = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first + + let shoppingItemURL = documentsDir?.appendingPathComponent("shoppingList.plist") + + return shoppingItemURL + + func saveToPersistentStore() { + + do { + + guard let shoppingListURL = shoppingListURL else { return } + + //This is the machine that we can run our array of stars through that turns it into a property list + let encoder = PropertyListEncoder() + // Try to turn the stars into a property list + let shoppingPlist = try encoder.encode(shopping) + // Save the stars plist to the location that we specified in the persistentFileURL + try readingPlist.write(to: readListURL) + + } catch { + print("Error saving star \(error)") + + } + + } + + + + +} + diff --git a/Shopping List/ShoppingItem.swift b/Shopping List/ShoppingItem.swift new file mode 100644 index 00000000..5976826c --- /dev/null +++ b/Shopping List/ShoppingItem.swift @@ -0,0 +1,19 @@ +// +// ShoppingItem.swift +// Shopping List +// +// Created by Drew Miller on 5/22/20. +// Copyright © 2020 Lambda School. All rights reserved. +// + +import Foundation +import UIKit + +struct ShoppingItem: Encodable { + let name: String + var purchased: Bool + let image: UIImage + +} + + diff --git a/Shopping List/ShoppingListCollectionViewController.swift b/Shopping List/ShoppingListCollectionViewController.swift new file mode 100644 index 00000000..5bc63352 --- /dev/null +++ b/Shopping List/ShoppingListCollectionViewController.swift @@ -0,0 +1,91 @@ +// +// ShoppingListCollectionViewController.swift +// Shopping List +// +// Created by Drew Miller on 5/22/20. +// Copyright © 2020 Lambda School. All rights reserved. +// + +import UIKit + +private let reuseIdentifier = "Cell" + +class ShoppingListCollectionViewController: UICollectionViewController { + + let itemNames = ["Apple", "Grapes", "Milk", "Muffin", "Popcorn", "Soda", "Strawberries"] + + override func viewDidLoad() { + super.viewDidLoad() + + // Uncomment the following line to preserve selection between presentations + // self.clearsSelectionOnViewWillAppear = false + + // Register cell classes + self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier) + + // Do any additional setup after loading the view. + } + + /* + // MARK: - Navigation + + // In a storyboard-based application, you will often want to do a little preparation before navigation + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + // Get the new view controller using [segue destinationViewController]. + // Pass the selected object to the new view controller. + } + */ + + // MARK: UICollectionViewDataSource + + override func numberOfSections(in collectionView: UICollectionView) -> Int { + // #warning Incomplete implementation, return the number of sections + return 0 + } + + + override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + // #warning Incomplete implementation, return the number of items + return 0 + } + + override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) + + // Configure the cell + + return cell + } + + // MARK: UICollectionViewDelegate + + /* + // Uncomment this method to specify if the specified item should be highlighted during tracking + override func collectionView(_ collectionView: UICollectionView, shouldHighlightItemAt indexPath: IndexPath) -> Bool { + return true + } + */ + + /* + // Uncomment this method to specify if the specified item should be selected + override func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool { + return true + } + */ + + /* + // Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item + override func collectionView(_ collectionView: UICollectionView, shouldShowMenuForItemAt indexPath: IndexPath) -> Bool { + return false + } + + override func collectionView(_ collectionView: UICollectionView, canPerformAction action: Selector, forItemAt indexPath: IndexPath, withSender sender: Any?) -> Bool { + return false + } + + override func collectionView(_ collectionView: UICollectionView, performAction action: Selector, forItemAt indexPath: IndexPath, withSender sender: Any?) { + + } + */ + +} diff --git a/Shopping List/ViewController.swift b/Shopping List/ViewController.swift deleted file mode 100644 index eecb48b5..00000000 --- a/Shopping List/ViewController.swift +++ /dev/null @@ -1,25 +0,0 @@ -// -// ViewController.swift -// Shopping List -// -// Created by Spencer Curtis on 8/3/18. -// Copyright © 2018 Lambda School. All rights reserved. -// - -import UIKit - -class ViewController: UIViewController { - - override func viewDidLoad() { - super.viewDidLoad() - // Do any additional setup after loading the view, typically from a nib. - } - - override func didReceiveMemoryWarning() { - super.didReceiveMemoryWarning() - // Dispose of any resources that can be recreated. - } - - -} - diff --git a/Shopping List/Info.plist b/Shopping List/shoppingList.plist similarity index 100% rename from Shopping List/Info.plist rename to Shopping List/shoppingList.plist From 8ed091f9be7a634a6ad97b8a6ba46402da684a77 Mon Sep 17 00:00:00 2001 From: dmills14 Date: Fri, 22 May 2020 10:59:56 -0700 Subject: [PATCH 2/3] more setup --- Default-568h@2x.png | Bin 0 -> 18594 bytes Shopping List.xcodeproj/project.pbxproj | 13 +++++++++---- Shopping List/AppDelegate.swift | 2 +- Shopping List/FileManager.swift | 2 +- .../{shoppingList.plist => Info.plist} | 0 Shopping List/ShoppingItem.swift | 2 +- 6 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 Default-568h@2x.png rename Shopping List/{shoppingList.plist => Info.plist} (100%) diff --git a/Default-568h@2x.png b/Default-568h@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..0891b7aabfcf3422423b109c8beed2bab838c607 GIT binary patch literal 18594 zcmeI4X;f257Jx&9fS`ixvS;&$x8J@slQFSel)6zJN=?13FB7H(lQjRkSy8x_-S~tvu2gzn1oS+dLcF#eqtq$ z%tf9TTvX?`)R@}3uBI;jzS-=ZR-Td&MHaS&;!0?Ni*#$#`n*~CcQK)Q9vAQ~TUpnI!j)a2biYK^R)M~A5wUDZhx?ULMX z3x1P&qt=trOY6P2U67L=m=U?F|5#Uj(eCueNTZaHs_ceWiHeET+j+tp3Jt9g(ekqP z2WOvfR{qV+9r+o4J5?qK>7;;^+I7tGv-i)es$X_D=EoKF+S?zsyj^oRFElP}c}JT< zd8SUs-?O?}2YD#ngKbnHgzHBcboxK_2r9l(?eNCl-pEzkJm}fY?WC*jnS?VBE4EpY zO$fEejz6fU;W2Kl>JeQBZBl-%Irg`obSlg*@4QB;Dd1H7^Oi5wvt4d{RZ!8Og?^aE z)k0$1g+V3fd(gdQ3d&q2q-FL*uy#}|bc^=VhFsl0jBgUGJ+-s3U8MK9A!YJJMxpci z5hJ%|{DwV48fZn0{n5l$N_KcSb#NKE4plB`9I6Zt=Z!~-zw0{9tg$L&Ju1F0X)Cy8 zKF;(&lJ>x)Jw(=;p~sF(Sd9VWGwFE2rnyS9!f^DZ8+aCLq zQ};>lcJ1GDLqjm6Hd>|Eabno@P`~Bn(~6^aD_#yoEH(a?Nm1S<;S+hSxI5d16^<1lEM3NPFi zkqPrpL)+ zgnseFikg`gJVBha1&7C4;O6>h=dt~`ND+;Zd?W(4v2JIb7Pt>Td42%M-Ju-XAH#Pns762L}K3 zDhvsRqN0Ni(1UrishD2YvV?4*h2iFj$+&N||Fn$4n|^NSU+o?~jq`0jVQt8T9l{7b zXiwwODFh2V!Q6sqP9S>WH$oOf$N~=d0-bqTlD61!=`&0eAP-F>XN?*|gtOXX{ zQVTWyYo4ZK0GAw!GHf|pz9`D;-bbb*5LBX*{bnz|+)$@&P9|ORM2o?95{;ejvo&r- zq8cBhTN6nn)7~W>54U)%-F_-b?YKdfk5I8MHcuzBD5)!;yv#Z&R&^y=@=>VTIMy#r zX&U<=BsPkdqcMe<_}2+>H%XKyrr5ZR8_KVe>ZqYN z^=^~TFD};;rHJ$U;{~w^hYojl4hRI@SH$^K{YEo=sg)WY87r!*7blQK&qnpDo0`Vn zkl)9u9g=mCh&ZCJS(L4yN3k0kQ zuvg$h2KEEk51T+O0JQ+r0`R>g{jvqM0Mr6d3qUOZwE!?PI7HY@CE|dr sfw?Q;rAv?G4&^^8-z_>&sWXMxvD*gPOU4CBe-*@OtE+wfmVJNyHv)PfH~;_u literal 0 HcmV?d00001 diff --git a/Shopping List.xcodeproj/project.pbxproj b/Shopping List.xcodeproj/project.pbxproj index ec6fd424..6df40117 100644 --- a/Shopping List.xcodeproj/project.pbxproj +++ b/Shopping List.xcodeproj/project.pbxproj @@ -14,6 +14,7 @@ 56F7A4CF247821C9006FBE7F /* ShoppingItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F7A4CE247821C9006FBE7F /* ShoppingItem.swift */; }; 56F7A4D1247827A2006FBE7F /* ShoppingListCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F7A4D0247827A2006FBE7F /* ShoppingListCollectionViewController.swift */; }; 56F7A4D5247828DB006FBE7F /* FileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F7A4D4247828DB006FBE7F /* FileManager.swift */; }; + 56F7A4D724782CE2006FBE7F /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 56F7A4D624782CE1006FBE7F /* Default-568h@2x.png */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -22,10 +23,11 @@ 4613E91621143BFC00E7FF73 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 4613E91821143BFD00E7FF73 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 4613E91B21143BFD00E7FF73 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; - 4613E91D21143BFD00E7FF73 /* shoppingList.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = shoppingList.plist; sourceTree = ""; }; + 4613E91D21143BFD00E7FF73 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 56F7A4CE247821C9006FBE7F /* ShoppingItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoppingItem.swift; sourceTree = ""; }; 56F7A4D0247827A2006FBE7F /* ShoppingListCollectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoppingListCollectionViewController.swift; sourceTree = ""; }; 56F7A4D4247828DB006FBE7F /* FileManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileManager.swift; sourceTree = ""; }; + 56F7A4D624782CE1006FBE7F /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -42,6 +44,7 @@ 4613E90521143BFC00E7FF73 = { isa = PBXGroup; children = ( + 56F7A4D624782CE1006FBE7F /* Default-568h@2x.png */, 4613E91021143BFC00E7FF73 /* Shopping List */, 4613E90F21143BFC00E7FF73 /* Products */, ); @@ -65,7 +68,7 @@ 56F7A4D4247828DB006FBE7F /* FileManager.swift */, 4613E91821143BFD00E7FF73 /* Assets.xcassets */, 4613E91A21143BFD00E7FF73 /* LaunchScreen.storyboard */, - 4613E91D21143BFD00E7FF73 /* shoppingList.plist */, + 4613E91D21143BFD00E7FF73 /* Info.plist */, ); path = "Shopping List"; sourceTree = ""; @@ -102,6 +105,7 @@ TargetAttributes = { 4613E90D21143BFC00E7FF73 = { CreatedOnToolsVersion = 9.4.1; + LastSwiftMigration = 1150; }; }; }; @@ -129,6 +133,7 @@ buildActionMask = 2147483647; files = ( 4613E91C21143BFD00E7FF73 /* LaunchScreen.storyboard in Resources */, + 56F7A4D724782CE2006FBE7F /* Default-568h@2x.png in Resources */, 4613E91921143BFD00E7FF73 /* Assets.xcassets in Resources */, 4613E91721143BFC00E7FF73 /* Main.storyboard in Resources */, ); @@ -297,7 +302,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = "com.LambdaSchool.Shopping-List"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -315,7 +320,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = "com.LambdaSchool.Shopping-List"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/Shopping List/AppDelegate.swift b/Shopping List/AppDelegate.swift index cdf8092c..6d5984e0 100644 --- a/Shopping List/AppDelegate.swift +++ b/Shopping List/AppDelegate.swift @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true } diff --git a/Shopping List/FileManager.swift b/Shopping List/FileManager.swift index cce8c8e1..d6379443 100644 --- a/Shopping List/FileManager.swift +++ b/Shopping List/FileManager.swift @@ -31,7 +31,7 @@ var shoppingListURL: URL? { // Try to turn the stars into a property list let shoppingPlist = try encoder.encode(shopping) // Save the stars plist to the location that we specified in the persistentFileURL - try readingPlist.write(to: readListURL) + try shoppingPlist.write(to: shoppingListURL) } catch { print("Error saving star \(error)") diff --git a/Shopping List/shoppingList.plist b/Shopping List/Info.plist similarity index 100% rename from Shopping List/shoppingList.plist rename to Shopping List/Info.plist diff --git a/Shopping List/ShoppingItem.swift b/Shopping List/ShoppingItem.swift index 5976826c..0a7c5cfe 100644 --- a/Shopping List/ShoppingItem.swift +++ b/Shopping List/ShoppingItem.swift @@ -12,7 +12,7 @@ import UIKit struct ShoppingItem: Encodable { let name: String var purchased: Bool - let image: UIImage + let image: String } From 1fa24acdc0a236b75f010acc2101e1b96b6d37a7 Mon Sep 17 00:00:00 2001 From: dmills14 Date: Mon, 25 May 2020 11:36:52 -0700 Subject: [PATCH 3/3] cell view controller --- Shopping List.xcodeproj/project.pbxproj | 4 + Shopping List/Base.lproj/Main.storyboard | 90 +++++++++++++++++-- Shopping List/FileManager.swift | 17 ++-- Shopping List/ShoppingItem.swift | 8 +- .../ShoppingItemCollectionViewCell.swift | 19 ++++ ...ShoppingListCollectionViewController.swift | 2 - 6 files changed, 121 insertions(+), 19 deletions(-) create mode 100644 Shopping List/ShoppingItemCollectionViewCell.swift diff --git a/Shopping List.xcodeproj/project.pbxproj b/Shopping List.xcodeproj/project.pbxproj index 6df40117..74f882f5 100644 --- a/Shopping List.xcodeproj/project.pbxproj +++ b/Shopping List.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 4613E91721143BFC00E7FF73 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4613E91521143BFC00E7FF73 /* Main.storyboard */; }; 4613E91921143BFD00E7FF73 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4613E91821143BFD00E7FF73 /* Assets.xcassets */; }; 4613E91C21143BFD00E7FF73 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4613E91A21143BFD00E7FF73 /* LaunchScreen.storyboard */; }; + 56859385247C467F007A44EE /* ShoppingItemCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56859384247C467F007A44EE /* ShoppingItemCollectionViewCell.swift */; }; 56F7A4CF247821C9006FBE7F /* ShoppingItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F7A4CE247821C9006FBE7F /* ShoppingItem.swift */; }; 56F7A4D1247827A2006FBE7F /* ShoppingListCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F7A4D0247827A2006FBE7F /* ShoppingListCollectionViewController.swift */; }; 56F7A4D5247828DB006FBE7F /* FileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56F7A4D4247828DB006FBE7F /* FileManager.swift */; }; @@ -24,6 +25,7 @@ 4613E91821143BFD00E7FF73 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 4613E91B21143BFD00E7FF73 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 4613E91D21143BFD00E7FF73 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 56859384247C467F007A44EE /* ShoppingItemCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoppingItemCollectionViewCell.swift; sourceTree = ""; }; 56F7A4CE247821C9006FBE7F /* ShoppingItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoppingItem.swift; sourceTree = ""; }; 56F7A4D0247827A2006FBE7F /* ShoppingListCollectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoppingListCollectionViewController.swift; sourceTree = ""; }; 56F7A4D4247828DB006FBE7F /* FileManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileManager.swift; sourceTree = ""; }; @@ -64,6 +66,7 @@ 56F7A4CE247821C9006FBE7F /* ShoppingItem.swift */, 4613E91121143BFC00E7FF73 /* AppDelegate.swift */, 4613E91521143BFC00E7FF73 /* Main.storyboard */, + 56859384247C467F007A44EE /* ShoppingItemCollectionViewCell.swift */, 56F7A4D0247827A2006FBE7F /* ShoppingListCollectionViewController.swift */, 56F7A4D4247828DB006FBE7F /* FileManager.swift */, 4613E91821143BFD00E7FF73 /* Assets.xcassets */, @@ -146,6 +149,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 56859385247C467F007A44EE /* ShoppingItemCollectionViewCell.swift in Sources */, 56F7A4CF247821C9006FBE7F /* ShoppingItem.swift in Sources */, 56F7A4D1247827A2006FBE7F /* ShoppingListCollectionViewController.swift in Sources */, 4613E91221143BFC00E7FF73 /* AppDelegate.swift in Sources */, diff --git a/Shopping List/Base.lproj/Main.storyboard b/Shopping List/Base.lproj/Main.storyboard index 468a77fa..b0c952b0 100644 --- a/Shopping List/Base.lproj/Main.storyboard +++ b/Shopping List/Base.lproj/Main.storyboard @@ -18,19 +18,52 @@ - + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + @@ -38,7 +71,7 @@ - + @@ -48,7 +81,7 @@ - + @@ -57,14 +90,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/Shopping List/FileManager.swift b/Shopping List/FileManager.swift index d6379443..b9a27cfe 100644 --- a/Shopping List/FileManager.swift +++ b/Shopping List/FileManager.swift @@ -8,9 +8,14 @@ import Foundation -var shopping: [ShoppingItem] = [] +class ShoppingListControler { -var shoppingListURL: URL? { +var shoppingList: [ShoppingItem] = [] + +let itemNames = ["Apple", "Grapes", "Milk", "Muffin", "Popcorn", "Soda", "Strawberries"] + + +private var shoppingListURL: URL? { let fileManager = FileManager.default @@ -19,6 +24,8 @@ var shoppingListURL: URL? { let shoppingItemURL = documentsDir?.appendingPathComponent("shoppingList.plist") return shoppingItemURL + +} func saveToPersistentStore() { @@ -29,7 +36,7 @@ var shoppingListURL: URL? { //This is the machine that we can run our array of stars through that turns it into a property list let encoder = PropertyListEncoder() // Try to turn the stars into a property list - let shoppingPlist = try encoder.encode(shopping) + let shoppingPlist = try encoder.encode(shoppingList) // Save the stars plist to the location that we specified in the persistentFileURL try shoppingPlist.write(to: shoppingListURL) @@ -40,8 +47,6 @@ var shoppingListURL: URL? { } - - - } + diff --git a/Shopping List/ShoppingItem.swift b/Shopping List/ShoppingItem.swift index 0a7c5cfe..3dec2a1f 100644 --- a/Shopping List/ShoppingItem.swift +++ b/Shopping List/ShoppingItem.swift @@ -9,10 +9,10 @@ import Foundation import UIKit -struct ShoppingItem: Encodable { - let name: String - var purchased: Bool - let image: String +struct ShoppingItem: Codable, Equatable { + var name: String + var purchased: Bool = false + var image: String } diff --git a/Shopping List/ShoppingItemCollectionViewCell.swift b/Shopping List/ShoppingItemCollectionViewCell.swift new file mode 100644 index 00000000..6d22825c --- /dev/null +++ b/Shopping List/ShoppingItemCollectionViewCell.swift @@ -0,0 +1,19 @@ +// +// ShoppingItemCollectionViewCell.swift +// Shopping List +// +// Created by Drew Miller on 5/25/20. +// Copyright © 2020 Lambda School. All rights reserved. +// + +import UIKit + +class ShoppingItemCollectionViewCell: UICollectionViewCell { + + //Outlets + @IBOutlet weak var hasBeenAdded: UILabel! + @IBOutlet weak var shoppingItemImage: UIImageView! + @IBOutlet weak var itemLabel: UILabel! + + +} diff --git a/Shopping List/ShoppingListCollectionViewController.swift b/Shopping List/ShoppingListCollectionViewController.swift index 5bc63352..c269ef07 100644 --- a/Shopping List/ShoppingListCollectionViewController.swift +++ b/Shopping List/ShoppingListCollectionViewController.swift @@ -11,8 +11,6 @@ import UIKit private let reuseIdentifier = "Cell" class ShoppingListCollectionViewController: UICollectionViewController { - - let itemNames = ["Apple", "Grapes", "Milk", "Muffin", "Popcorn", "Soda", "Strawberries"] override func viewDidLoad() { super.viewDidLoad()