Added model and mvc
This commit is contained in:
18
TrashTrack/CalendarView.swift
Normal file
18
TrashTrack/CalendarView.swift
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
//
|
||||||
|
// CalendarView.swift
|
||||||
|
// TrashTrack
|
||||||
|
//
|
||||||
|
// Created by Oliver Hnát on 12.01.2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct CalendarView: View {
|
||||||
|
var body: some View {
|
||||||
|
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
CalendarView()
|
||||||
|
}
|
||||||
18
TrashTrack/DayView.swift
Normal file
18
TrashTrack/DayView.swift
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
//
|
||||||
|
// DayView.swift
|
||||||
|
// TrashTrack
|
||||||
|
//
|
||||||
|
// Created by Oliver Hnát on 12.01.2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct DayView: View {
|
||||||
|
var body: some View {
|
||||||
|
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
DayView()
|
||||||
|
}
|
||||||
83
TrashTrack/TrashModel.swift
Normal file
83
TrashTrack/TrashModel.swift
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
//
|
||||||
|
// TrashModel.swift
|
||||||
|
// TrashTrack
|
||||||
|
//
|
||||||
|
// Created by Oliver Hnát on 12.01.2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct Trash {
|
||||||
|
var type: String
|
||||||
|
var color: Color
|
||||||
|
var image: Image
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TrashEvent: Identifiable {
|
||||||
|
var id: Int
|
||||||
|
var trash: Trash
|
||||||
|
var date: Date
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TrashModel {
|
||||||
|
var trashTypes: [Trash]
|
||||||
|
var trashEvents: [TrashEvent]
|
||||||
|
|
||||||
|
init() {
|
||||||
|
self.trashTypes = [
|
||||||
|
Trash(type: "plastic", color: Color.orange, image: Image(systemName: "waterbottle")),
|
||||||
|
Trash(type: "paper", color: Color.orange, image: Image(systemName: "newspaper")),
|
||||||
|
Trash(type: "bio", color: Color.orange, image: Image(systemName: "tree")),
|
||||||
|
Trash(type: "residual", color: Color.orange, image: Image(systemName: "trash"))
|
||||||
|
]
|
||||||
|
|
||||||
|
self.trashEvents = []
|
||||||
|
let numberOfEvents = 3
|
||||||
|
for i in 0..<numberOfEvents {
|
||||||
|
self.trashEvents.append(
|
||||||
|
TrashEvent(
|
||||||
|
id: i,
|
||||||
|
trash: self.trashTypes[0],
|
||||||
|
date: Calendar.current.date(byAdding: .day, value: 3 + 7*i, to: Date())!
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i in 0..<numberOfEvents {
|
||||||
|
self.trashEvents.append(
|
||||||
|
TrashEvent(
|
||||||
|
id: i + 4 + 7,
|
||||||
|
trash: self.trashTypes[1],
|
||||||
|
date: Calendar.current.date(byAdding: .day, value: 4 + 7 + 7*i, to: Date())!
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i in 0..<numberOfEvents {
|
||||||
|
self.trashEvents.append(
|
||||||
|
TrashEvent(
|
||||||
|
id: i + 5,
|
||||||
|
trash: self.trashTypes[2],
|
||||||
|
date: Calendar.current.date(byAdding: .day, value: 5 + 7*i, to: Date())!
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i in 0..<numberOfEvents {
|
||||||
|
self.trashEvents.append(
|
||||||
|
TrashEvent(
|
||||||
|
id: i + 6 + 7,
|
||||||
|
trash: self.trashTypes[3],
|
||||||
|
date: Calendar.current.date(byAdding: .day, value: 6 + 7 + 7*i, to: Date())!
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
print(self.trashEvents)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTrashEvents() -> [TrashEvent] {
|
||||||
|
return self.trashEvents
|
||||||
|
}
|
||||||
|
}
|
||||||
17
TrashTrack/TrashModelView.swift
Normal file
17
TrashTrack/TrashModelView.swift
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
//
|
||||||
|
// TrashModelView.swift
|
||||||
|
// TrashTrack
|
||||||
|
//
|
||||||
|
// Created by Oliver Hnát on 12.01.2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
class TrashModelView {
|
||||||
|
let model = TrashModel()
|
||||||
|
|
||||||
|
func getTrashEvents() -> [TrashEvent] {
|
||||||
|
return model.trashEvents
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user