Skip to content

Instantly share code, notes, and snippets.

@tgunr
Created October 2, 2019 23:21
Show Gist options
  • Save tgunr/ae83aa8cc3834c0a6c6a9145cb507bea to your computer and use it in GitHub Desktop.
Save tgunr/ae83aa8cc3834c0a6c6a9145cb507bea to your computer and use it in GitHub Desktop.
//
// DosageDetail.swift
// myTracking
//
// Created by Dave Carlton on 10/1/19.
// Copyright © 2019 Dave Carlton. All rights reserved.
//
import SwiftUI
struct DosageDetail: View {
@State var medication: Medication
var dateFormatter: DateFormatter {
let formatter = DateFormatter()
formatter.dateStyle = .long
return formatter
}
var body: some View {
let dose = $medication.dosage
let doesStr = String(describing: dose)
let stack = VStack {
HStack{
Text("\(medication.name) Dosage")
}
Form {
Section(header: Text("Dosage settings")) {
HStack {
Stepper(value: $medication.dosage, in: 1...10) {
Text(doesStr)
}
// TextField("0", value: $medication.dosage)
}
}
Section(header: Text("Time settings")) {
Picker(selection: .constant(1), label: Text("Interval")) {
Text("Daily").tag(1)
Text("Hours").tag(2)
}
// DatePicker<Label: View>(selection: interval, in: ...Date(), displayedComponents: .hourAndMinute) {
// Text("Starting")
// }
}
Button(action: {
do {
try self.medication.save(CoreDataManager.shared.mainContext)
} catch {
print("Save failed")
}
}) {
Text("Save")
}
}
}
return stack
}
}
struct DosageDetail_Previews: PreviewProvider {
static var previews: some View {
let userData = UserData()
let medication = userData.medications[0]
return DosageDetail(medication: medication)
.environmentObject(userData)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment