Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update data model #1

Merged
merged 1 commit into from Mar 20, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -4,5 +4,4 @@ This is demo app for displaying a list of recipes.

Main View | Detailed View
:-------------------------:|:-------------------------:
<img src="./screenshots/demo1.png" width=300>| <img src="./screenshots/demo2.png" width=300>

<img src="./screenshots/demo.png" width=300>| <img src="./screenshots/demo2.png" width=300>
12 changes: 8 additions & 4 deletions RecipeList.xcodeproj/project.pbxproj
Expand Up @@ -11,11 +11,12 @@
1B01F6AF29C74C92002E8674 /* RecipeListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B01F6AE29C74C92002E8674 /* RecipeListView.swift */; };
1B01F6B129C74C93002E8674 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1B01F6B029C74C93002E8674 /* Assets.xcassets */; };
1B01F6B429C74C93002E8674 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1B01F6B329C74C93002E8674 /* Preview Assets.xcassets */; };
1B01F6C029C74D88002E8674 /* recipes.json in Resources */ = {isa = PBXBuildFile; fileRef = 1B01F6BF29C74D88002E8674 /* recipes.json */; };
1B01F6C229C74E0A002E8674 /* Recipe.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B01F6C129C74E0A002E8674 /* Recipe.swift */; };
1B01F6C429C74F25002E8674 /* RecipeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B01F6C329C74F25002E8674 /* RecipeModel.swift */; };
1B01F6C629C75066002E8674 /* DataService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B01F6C529C75066002E8674 /* DataService.swift */; };
1B01F6C929C76E12002E8674 /* RecipeDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B01F6C829C76E12002E8674 /* RecipeDetailView.swift */; };
1B01F71329C85CB1002E8674 /* RecipeTabView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B01F71229C85CB1002E8674 /* RecipeTabView.swift */; };
1B01F74A29C88BA4002E8674 /* recipes.json in Resources */ = {isa = PBXBuildFile; fileRef = 1B01F74929C88BA4002E8674 /* recipes.json */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -24,11 +25,12 @@
1B01F6AE29C74C92002E8674 /* RecipeListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecipeListView.swift; sourceTree = "<group>"; };
1B01F6B029C74C93002E8674 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
1B01F6B329C74C93002E8674 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
1B01F6BF29C74D88002E8674 /* recipes.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = recipes.json; sourceTree = "<group>"; };
1B01F6C129C74E0A002E8674 /* Recipe.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Recipe.swift; sourceTree = "<group>"; };
1B01F6C329C74F25002E8674 /* RecipeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecipeModel.swift; sourceTree = "<group>"; };
1B01F6C529C75066002E8674 /* DataService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataService.swift; sourceTree = "<group>"; };
1B01F6C829C76E12002E8674 /* RecipeDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecipeDetailView.swift; sourceTree = "<group>"; };
1B01F71229C85CB1002E8674 /* RecipeTabView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecipeTabView.swift; sourceTree = "<group>"; };
1B01F74929C88BA4002E8674 /* recipes.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = recipes.json; path = ../../../../../../Downloads/recipes.json; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -86,6 +88,7 @@
children = (
1B01F6AE29C74C92002E8674 /* RecipeListView.swift */,
1B01F6C829C76E12002E8674 /* RecipeDetailView.swift */,
1B01F71229C85CB1002E8674 /* RecipeTabView.swift */,
);
path = Views;
sourceTree = "<group>";
Expand All @@ -101,7 +104,7 @@
1B01F6BC29C74CD0002E8674 /* Data */ = {
isa = PBXGroup;
children = (
1B01F6BF29C74D88002E8674 /* recipes.json */,
1B01F74929C88BA4002E8674 /* recipes.json */,
);
path = Data;
sourceTree = "<group>";
Expand Down Expand Up @@ -181,8 +184,8 @@
buildActionMask = 2147483647;
files = (
1B01F6B429C74C93002E8674 /* Preview Assets.xcassets in Resources */,
1B01F6C029C74D88002E8674 /* recipes.json in Resources */,
1B01F6B129C74C93002E8674 /* Assets.xcassets in Resources */,
1B01F74A29C88BA4002E8674 /* recipes.json in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -199,6 +202,7 @@
1B01F6AF29C74C92002E8674 /* RecipeListView.swift in Sources */,
1B01F6AD29C74C92002E8674 /* RecipeListApp.swift in Sources */,
1B01F6C629C75066002E8674 /* DataService.swift in Sources */,
1B01F71329C85CB1002E8674 /* RecipeTabView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
177 changes: 0 additions & 177 deletions RecipeList/Data/recipes.json

This file was deleted.

12 changes: 11 additions & 1 deletion RecipeList/Models/Recipe.swift
Expand Up @@ -18,6 +18,16 @@ class Recipe: Identifiable, Decodable {
var prepTime:String
var cookTime:String
var servings:Int
var ingredients:[String]
var ingredients:[Ingredients]
var directions:[String]
var highlights:[String]
}

class Ingredients: Identifiable, Decodable {

var id:UUID? = UUID()
var name:String
var num:Int?
var denom:Int?
var unit:String?
}
2 changes: 1 addition & 1 deletion RecipeList/RecipeListApp.swift
Expand Up @@ -11,7 +11,7 @@ import SwiftUI
struct RecipeListApp: App {
var body: some Scene {
WindowGroup {
RecipeListView()
RecipeTabView()
}
}
}
4 changes: 4 additions & 0 deletions RecipeList/Services/DataService.swift
Expand Up @@ -30,6 +30,10 @@ class DataService {

for r in recipeData {
r.id = UUID()

for i in r.ingredients {
i.id = UUID()
}
}
return recipeData
}
Expand Down
4 changes: 2 additions & 2 deletions RecipeList/Views/RecipeDetailView.swift
Expand Up @@ -21,9 +21,9 @@ struct RecipeDetailView: View {
// MARK: Ingredients
VStack(alignment: .leading){
Text("Ingredients").font(.headline).padding([.bottom, .top], 5)
ForEach (recipe.ingredients, id: \.self) {
ForEach (recipe.ingredients) {
item in
Text("* " + item)
Text("* " + item.name)
}
}
.padding(.horizontal)
Expand Down
47 changes: 47 additions & 0 deletions RecipeList/Views/RecipeTabView.swift
@@ -0,0 +1,47 @@
//
// RecipeTabView.swift
// RecipeList
//
// Created by Nick Jüttner on 20.03.23.
//

import SwiftUI

struct RecipeTabView: View {

@ObservedObject var model = RecipeModel()

var body: some View {
VStack {
HStack{
Spacer()
Button(action: { print("Hello") } ) {
Image(systemName: "plus.circle.fill")
Text("Add Recipe")
}
Spacer()
}
TabView {
Text("Featured View").tabItem {
VStack {
Image(systemName: "star.fill")
Text("Featured")
}
}
RecipeListView()
.tabItem {
VStack {
Image(systemName: "list.bullet")
Text("List")
}
}.badge(model.recipes.count)
}
}
}
}

struct RecipeTabView_Previews: PreviewProvider {
static var previews: some View {
RecipeTabView()
}
}
Binary file added screenshots/demo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.