Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 32 additions & 7 deletions CoffeeTracker/CoffeeTracker/Beans/BeansCollectionViewOO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,22 @@ class BeansCollectionViewOO: NSObject, ObservableObject {
try fetchedBeanResultsController.performFetch()
beans = (fetchedBeanResultsController.fetchedObjects ?? []).map({ foundBean -> BeanModel in

let image = UIImage(data: foundBean.beanPhoto ?? Data())
guard let data = foundBean.beanPhoto else {

var savedImage = UIImage(systemName: SFSymbols.photo)!

if let image = image {
savedImage = image
return BeanModel(id: foundBean.id ?? UUID(),
name: foundBean.name ?? "",
style: foundBean.style ?? "",
buyAgain: foundBean.buyAgain,
roaster: foundBean.roaster ?? "",
roastedOn: foundBean.roastedOn ?? Date.distantPast,
boughtOn: foundBean.boughtOn ?? Date.now,
notes: foundBean.notes ?? "",
objectID: foundBean.objectID,
image: UIImage(systemName: SFSymbols.photo)!)
}

let image = UIImage(data: data)

return BeanModel(id: foundBean.id ?? UUID(),
name: foundBean.name ?? "",
style: foundBean.style ?? "",
Expand All @@ -50,7 +58,7 @@ class BeansCollectionViewOO: NSObject, ObservableObject {
boughtOn: foundBean.boughtOn ?? Date.now,
notes: foundBean.notes ?? "",
objectID: foundBean.objectID,
image: savedImage)
image: image!)
})
} catch {
print("Error")
Expand All @@ -61,6 +69,22 @@ class BeansCollectionViewOO: NSObject, ObservableObject {
extension BeansCollectionViewOO: NSFetchedResultsControllerDelegate {
func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
beans = (controller.fetchedObjects as? [Bean] ?? []).map({ foundBean -> BeanModel in
guard let data = foundBean.beanPhoto else {

return BeanModel(id: foundBean.id ?? UUID(),
name: foundBean.name ?? "",
style: foundBean.style ?? "",
buyAgain: foundBean.buyAgain,
roaster: foundBean.roaster ?? "",
roastedOn: foundBean.roastedOn ?? Date.distantPast,
boughtOn: foundBean.boughtOn ?? Date.now,
notes: foundBean.notes ?? "",
objectID: foundBean.objectID,
image: UIImage(systemName: SFSymbols.photo)!)
}

let image = UIImage(data: data)

return BeanModel(id: foundBean.id ?? UUID(),
name: foundBean.name ?? "",
style: foundBean.style ?? "",
Expand All @@ -69,7 +93,8 @@ extension BeansCollectionViewOO: NSFetchedResultsControllerDelegate {
roastedOn: foundBean.roastedOn ?? Date.distantPast,
boughtOn: foundBean.boughtOn ?? Date.now,
notes: foundBean.notes ?? "",
objectID: foundBean.objectID, image: UIImage())
objectID: foundBean.objectID,
image: image!)
})
}
}
4 changes: 3 additions & 1 deletion CoffeeTracker/CoffeeTracker/Beans/NewBeansView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ struct NewBeansView: View {
roaster: "",
roastedOn: Date(),
boughtOn: Date(),
notes: "", image: UIImage())
notes: "",
image: UIImage())

@State private var isImageSelected = false
@State var selectedImage = UIImage()
Expand All @@ -52,6 +53,7 @@ struct NewBeansView: View {
case .denied:
print("DENIED")
default:
print("\(status)")
print("IDK WHAT HAPPENED")
}
}
Expand Down