Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2e6ab68
initial commit
RichGibbs-prog May 22, 2020
dd31ff7
added a shopping item model
RichGibbs-prog May 22, 2020
68f49c8
I guess I haven't learned anything @mrflowers22
RichGibbs-prog May 22, 2020
2ae3155
I have no clue what I am doing
RichGibbs-prog May 22, 2020
4f2a78d
glad this is over with I will take my 1 with pride, I wanted to quit …
RichGibbs-prog May 22, 2020
f2f5973
I think I figured out this codable thing
RichGibbs-prog May 22, 2020
563d76c
added constraints to my detail view controller
RichGibbs-prog May 25, 2020
3e19307
xcode troubles
RichGibbs-prog May 25, 2020
e7006d7
the pictures show up now I need the label to change to added or not a…
RichGibbs-prog May 25, 2020
e98deef
trying to get the label to change
RichGibbs-prog May 25, 2020
8e08a9b
clicking on the collection view changes the label
RichGibbs-prog May 26, 2020
e5689e5
buttons working I think
RichGibbs-prog May 26, 2020
4bb371e
alert works
RichGibbs-prog May 26, 2020
eee3f0e
detail view label works but wrong number is being shown
RichGibbs-prog May 26, 2020
1b882fe
most recent commit
RichGibbs-prog May 26, 2020
091971a
fixed a little formatting error
RichGibbs-prog May 26, 2020
d7d0ce6
most recent commit
RichGibbs-prog May 26, 2020
397c298
I don't know what I did but now my label toggles
RichGibbs-prog May 26, 2020
38dcb77
everything works I believe I just need to add persistence now
RichGibbs-prog May 26, 2020
20ba787
persistance not working
RichGibbs-prog May 26, 2020
dbf8ebf
still having persistence issues
RichGibbs-prog May 26, 2020
d125701
xcode issues
RichGibbs-prog May 28, 2020
69444ce
Data persists throughout runs of apps I am still not sure If I am fol…
RichGibbs-prog May 28, 2020
a799800
@mrflowers22
RichGibbs-prog May 28, 2020
a6456a1
mvp
RichGibbs-prog May 28, 2020
945e8c1
minor bug fixes
RichGibbs-prog May 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 75 additions & 7 deletions Shopping List.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,30 @@

/* 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 */; };
B149E374247828A6004EF640 /* ShoppingItemController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B149E373247828A6004EF640 /* ShoppingItemController.swift */; };
B18018E4247C1605003B5B6A /* ShoppingListCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B18018E3247C1605003B5B6A /* ShoppingListCollectionViewController.swift */; };
B18018E6247C2AFE003B5B6A /* ShoppingListDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B18018E5247C2AFE003B5B6A /* ShoppingListDetailViewController.swift */; };
B18018E8247C3A3C003B5B6A /* ShoppingItemCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B18018E7247C3A3C003B5B6A /* ShoppingItemCollectionViewCell.swift */; };
B187DF10247F31DD00618D3A /* Keys.swift in Sources */ = {isa = PBXBuildFile; fileRef = B187DF0F247F31DD00618D3A /* Keys.swift */; };
B1DAC5632478255B00BE7822 /* ShoppingItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1DAC5622478255B00BE7822 /* ShoppingItemModel.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 = "<group>"; };
4613E91321143BFC00E7FF73 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
4613E91621143BFC00E7FF73 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
4613E91821143BFD00E7FF73 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
4613E91B21143BFD00E7FF73 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
4613E91D21143BFD00E7FF73 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
B149E373247828A6004EF640 /* ShoppingItemController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoppingItemController.swift; sourceTree = "<group>"; };
B18018E3247C1605003B5B6A /* ShoppingListCollectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoppingListCollectionViewController.swift; sourceTree = "<group>"; };
B18018E5247C2AFE003B5B6A /* ShoppingListDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ShoppingListDetailViewController.swift; path = "Shopping List/View Controllers/ShoppingListDetailViewController.swift"; sourceTree = SOURCE_ROOT; };
B18018E7247C3A3C003B5B6A /* ShoppingItemCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoppingItemCollectionViewCell.swift; sourceTree = "<group>"; };
B187DF0F247F31DD00618D3A /* Keys.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Keys.swift; path = "Shopping List/Model Controllers/Keys.swift"; sourceTree = SOURCE_ROOT; };
B1DAC5622478255B00BE7822 /* ShoppingItemModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoppingItemModel.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -54,14 +64,67 @@
4613E91021143BFC00E7FF73 /* Shopping List */ = {
isa = PBXGroup;
children = (
B18018E9247C3A43003B5B6A /* VIews */,
B1DAC561247824D100BE7822 /* Storyboards */,
B149E375247828AC004EF640 /* Model Controllers */,
B1DAC5642478255F00BE7822 /* Models */,
B1DAC560247824C400BE7822 /* View Controllers */,
B1DAC55F247824BB00BE7822 /* Resources */,
4613E91D21143BFD00E7FF73 /* Info.plist */,
);
path = "Shopping List";
sourceTree = "<group>";
};
B149E375247828AC004EF640 /* Model Controllers */ = {
isa = PBXGroup;
children = (
B149E373247828A6004EF640 /* ShoppingItemController.swift */,
);
path = "Model Controllers";
sourceTree = "<group>";
};
B18018E9247C3A43003B5B6A /* VIews */ = {
isa = PBXGroup;
children = (
B18018E7247C3A3C003B5B6A /* ShoppingItemCollectionViewCell.swift */,
);
path = VIews;
sourceTree = "<group>";
};
B1DAC55F247824BB00BE7822 /* Resources */ = {
isa = PBXGroup;
children = (
B187DF0F247F31DD00618D3A /* Keys.swift */,
4613E91121143BFC00E7FF73 /* AppDelegate.swift */,
4613E91321143BFC00E7FF73 /* ViewController.swift */,
4613E91521143BFC00E7FF73 /* Main.storyboard */,
4613E91821143BFD00E7FF73 /* Assets.xcassets */,
);
path = Resources;
sourceTree = "<group>";
};
B1DAC560247824C400BE7822 /* View Controllers */ = {
isa = PBXGroup;
children = (
B18018E5247C2AFE003B5B6A /* ShoppingListDetailViewController.swift */,
B18018E3247C1605003B5B6A /* ShoppingListCollectionViewController.swift */,
);
path = "View Controllers";
sourceTree = "<group>";
};
B1DAC561247824D100BE7822 /* Storyboards */ = {
isa = PBXGroup;
children = (
4613E91521143BFC00E7FF73 /* Main.storyboard */,
4613E91A21143BFD00E7FF73 /* LaunchScreen.storyboard */,
4613E91D21143BFD00E7FF73 /* Info.plist */,
);
path = "Shopping List";
path = Storyboards;
sourceTree = "<group>";
};
B1DAC5642478255F00BE7822 /* Models */ = {
isa = PBXGroup;
children = (
B1DAC5622478255B00BE7822 /* ShoppingItemModel.swift */,
);
path = "Models ";
sourceTree = "<group>";
};
/* End PBXGroup section */
Expand Down Expand Up @@ -135,7 +198,12 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
4613E91421143BFC00E7FF73 /* ViewController.swift in Sources */,
B18018E4247C1605003B5B6A /* ShoppingListCollectionViewController.swift in Sources */,
B18018E8247C3A3C003B5B6A /* ShoppingItemCollectionViewCell.swift in Sources */,
B187DF10247F31DD00618D3A /* Keys.swift in Sources */,
B1DAC5632478255B00BE7822 /* ShoppingItemModel.swift in Sources */,
B18018E6247C2AFE003B5B6A /* ShoppingListDetailViewController.swift in Sources */,
B149E374247828A6004EF640 /* ShoppingItemController.swift in Sources */,
4613E91221143BFC00E7FF73 /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
24 changes: 0 additions & 24 deletions Shopping List/Base.lproj/Main.storyboard

This file was deleted.

13 changes: 13 additions & 0 deletions Shopping List/Model Controllers/Keys.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// File.swift
// Shopping List
//
// Created by Richard Gibbs on 5/27/20.
// Copyright © 2020 Lambda School. All rights reserved.
//

import Foundation

extension String {
static var initializeItems = "initializeItems"
}
79 changes: 79 additions & 0 deletions Shopping List/Model Controllers/ShoppingItemController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// ShoppingItemController.swift
// Shopping List
//
// Created by Richard Gibbs on 5/22/20.
// Copyright © 2020 Lambda School. All rights reserved.
//

import Foundation



class ShoppingItemController: Codable {

let itemNames = ["Apple", "Grapes", "Milk", "Muffin", "Popcorn", "Soda", "Strawberries"]
var items: [ShoppingItem] = []
func createShoppingItem() {
for itemName in itemNames {
items.append(ShoppingItem(name: itemName, imageName: itemName))
}
saveToPersistentStore()
}

init() {
if UserDefaults.standard.bool(forKey: .initializeItems) != true {
createShoppingItem()
UserDefaults.standard.set(true, forKey: .initializeItems)
} else {
loadFromPersistentStore()
}
}

// I need to access the .added property of my shopping item and toggle between added and not added

// need an object

var persistentFileURL: URL? {
let fileManager = FileManager.default
guard let documentsDir = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first else { return nil }
let itemsURL = documentsDir.appendingPathComponent("items.plist")
return itemsURL
}

func saveToPersistentStore() {
guard let persistentFileURL = persistentFileURL else { return }
do {
let encoder = PropertyListEncoder()
let itemsPlist = try encoder.encode(items)
try itemsPlist.write(to: persistentFileURL)
} catch {
print("Error saving items: \(error)")
}
}

func loadFromPersistentStore() {
guard let persistentFileURL = persistentFileURL else { return }
do {
let itemsPlist = try Data(contentsOf: persistentFileURL)
let decoder = PropertyListDecoder()
let decodedItems = try decoder.decode([ShoppingItem].self, from: itemsPlist)
self.items = decodedItems
} catch {
print("Error loading items from plist: \(error)")
}
}

//Here is the opject
func updateShoppingList(for item: ShoppingItem) {
if let itemAdded = items.firstIndex(of: item) {
var shoppingItem = items[itemAdded]
shoppingItem.added.toggle()
print("\(shoppingItem.name) was updated to \(shoppingItem.added)")
items[itemAdded] = shoppingItem
saveToPersistentStore()
print(items.count)
}
}

}
29 changes: 29 additions & 0 deletions Shopping List/Models /ShoppingItemModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// ShoppingItemModel.swift
// Shopping List
//
// Created by Richard Gibbs on 5/22/20.
// Copyright © 2020 Lambda School. All rights reserved.
//

import Foundation
import UIKit

struct ShoppingItem: Codable, Equatable {
var name: String
var added: Bool = false
var imageName: String
var image: UIImage {
return UIImage(named: imageName)!
}
//
// init(name: String, imageName: String) {
// self.name = name
// self.imageName = imageName
// }


}



Loading