Einrad Model Container View
This commit is contained in:
parent
2c898e5412
commit
57c56a4235
6 changed files with 78 additions and 7 deletions
17
App.swift
17
App.swift
|
|
@ -1,5 +1,6 @@
|
|||
// https://carrascomolina.com
|
||||
import SwiftUI
|
||||
import SwiftData
|
||||
|
||||
@main
|
||||
struct TheSwiftWeek: App {
|
||||
|
|
@ -8,13 +9,15 @@ struct TheSwiftWeek: App {
|
|||
|
||||
var body: some Scene {
|
||||
WindowGroup {
|
||||
VStack{
|
||||
|
||||
|
||||
ContentView()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// ContentView()
|
||||
|
||||
UnicycleView()
|
||||
|
||||
|
||||
}.modelContainer(for: Unicycle.self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,10 @@
|
|||
"comment" : "A button that adds a new bike to the list of bikes.",
|
||||
"isCommentAutoGenerated" : true
|
||||
},
|
||||
"Add unicycle" : {
|
||||
"comment" : "A button that adds a new unicycle to the list.",
|
||||
"isCommentAutoGenerated" : true
|
||||
},
|
||||
"Bikes" : {
|
||||
"comment" : "The title of the list section in the BikeSwipe tab.",
|
||||
"isCommentAutoGenerated" : true
|
||||
|
|
@ -29,6 +33,10 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"Einrad von %@" : {
|
||||
"comment" : "A list item displaying the creation date of a unicycle.",
|
||||
"isCommentAutoGenerated" : true
|
||||
},
|
||||
"Enter Emoji" : {
|
||||
"comment" : "A label for an text field where the user can enter an emoji.",
|
||||
"isCommentAutoGenerated" : true
|
||||
|
|
@ -37,6 +45,10 @@
|
|||
"comment" : "A word that is displayed when the number is a multiple of 3.",
|
||||
"isCommentAutoGenerated" : true
|
||||
},
|
||||
"Hello, World!" : {
|
||||
"comment" : "A greeting message displayed in the preview.",
|
||||
"isCommentAutoGenerated" : true
|
||||
},
|
||||
"My Vehicle" : {
|
||||
"extractionState" : "manual",
|
||||
"localizations" : {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@
|
|||
FB2F07E92EA7CB25002BD499 /* ListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB2F07E82EA7CB25002BD499 /* ListView.swift */; };
|
||||
FB79FE462EA8CFD20011678F /* RangeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB79FE452EA8CFD20011678F /* RangeView.swift */; };
|
||||
FB79FE482EA8F74F0011678F /* BikeSwipeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB79FE472EA8F74F0011678F /* BikeSwipeView.swift */; };
|
||||
FB79FE4A2EA906CC0011678F /* UnicycleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB79FE492EA906CC0011678F /* UnicycleView.swift */; };
|
||||
FB79FE4C2EA9071F0011678F /* Unicycle.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB79FE4B2EA9071F0011678F /* Unicycle.swift */; };
|
||||
FBA00D6D2EA78411006F8B9A /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = FBA00D6C2EA78411006F8B9A /* Localizable.xcstrings */; };
|
||||
FBA00D6F2EA78853006F8B9A /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBA00D6E2EA78850006F8B9A /* Color.swift */; };
|
||||
FBA00D712EA7A839006F8B9A /* PaddingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBA00D702EA7A830006F8B9A /* PaddingView.swift */; };
|
||||
|
|
@ -32,6 +34,8 @@
|
|||
FB2F07E82EA7CB25002BD499 /* ListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListView.swift; sourceTree = "<group>"; };
|
||||
FB79FE452EA8CFD20011678F /* RangeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RangeView.swift; sourceTree = "<group>"; };
|
||||
FB79FE472EA8F74F0011678F /* BikeSwipeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BikeSwipeView.swift; sourceTree = "<group>"; };
|
||||
FB79FE492EA906CC0011678F /* UnicycleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnicycleView.swift; sourceTree = "<group>"; };
|
||||
FB79FE4B2EA9071F0011678F /* Unicycle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Unicycle.swift; sourceTree = "<group>"; };
|
||||
FBA00D6C2EA78411006F8B9A /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = "<group>"; };
|
||||
FBA00D6E2EA78850006F8B9A /* Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = "<group>"; };
|
||||
FBA00D702EA7A830006F8B9A /* PaddingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaddingView.swift; sourceTree = "<group>"; };
|
||||
|
|
@ -70,6 +74,8 @@
|
|||
0CC14A882E92EEA900271E8D /* Playground.swift */,
|
||||
FBA6FA612EA76AAD00C373EC /* BikeView.swift */,
|
||||
FB79FE472EA8F74F0011678F /* BikeSwipeView.swift */,
|
||||
FB79FE492EA906CC0011678F /* UnicycleView.swift */,
|
||||
FB79FE4B2EA9071F0011678F /* Unicycle.swift */,
|
||||
FBA6FA652EA7725A00C373EC /* TrainView.swift */,
|
||||
FB2F07E82EA7CB25002BD499 /* ListView.swift */,
|
||||
FB79FE452EA8CFD20011678F /* RangeView.swift */,
|
||||
|
|
@ -167,8 +173,10 @@
|
|||
FB79FE462EA8CFD20011678F /* RangeView.swift in Sources */,
|
||||
FBA6FA662EA7725A00C373EC /* TrainView.swift in Sources */,
|
||||
FBA00D752EA7ACE1006F8B9A /* SwapperView.swift in Sources */,
|
||||
FB79FE4C2EA9071F0011678F /* Unicycle.swift in Sources */,
|
||||
0CC14A892E92EEA900271E8D /* Playground.swift in Sources */,
|
||||
FBA6FA642EA7715E00C373EC /* Extentions.swift in Sources */,
|
||||
FB79FE4A2EA906CC0011678F /* UnicycleView.swift in Sources */,
|
||||
0CC14A872E92EC7B00271E8D /* App.swift in Sources */,
|
||||
FBA00D732EA7A96C006F8B9A /* ContentView.swift in Sources */,
|
||||
FBA00D6F2EA78853006F8B9A /* Color.swift in Sources */,
|
||||
|
|
|
|||
Binary file not shown.
13
Unicycle.swift
Normal file
13
Unicycle.swift
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import SwiftData
|
||||
import SwiftUI
|
||||
|
||||
|
||||
@Model class Unicycle{
|
||||
var createdAt: Date = Date()
|
||||
init(createdAt: Date) {
|
||||
self.createdAt = createdAt
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
35
UnicycleView.swift
Normal file
35
UnicycleView.swift
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import SwiftData
|
||||
import SwiftUI
|
||||
|
||||
struct UnicycleView2: View {
|
||||
var body: some View {
|
||||
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
|
||||
}
|
||||
}
|
||||
|
||||
struct UnicycleView: View {
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
@Query private var unis: [Unicycle]
|
||||
|
||||
var body: some View {
|
||||
Button("Add unicycle") {
|
||||
modelContext.insert(Unicycle(createdAt: Date()))
|
||||
}
|
||||
List{
|
||||
ForEach(unis) { uni in
|
||||
Text("Einrad von \(uni.createdAt.description)")
|
||||
}.onDelete {
|
||||
for index in $0 {
|
||||
|
||||
|
||||
|
||||
modelContext.delete(unis[index])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
UnicycleView2()
|
||||
}
|
||||
Loading…
Reference in a new issue