diff --git a/ProIPhone_Ch07_SharingDataBetweenStructures.xcodeproj/project.xcworkspace/xcuserdata/neddington.xcuserdatad/UserInterfaceState.xcuserstate b/ProIPhone_Ch07_SharingDataBetweenStructures.xcodeproj/project.xcworkspace/xcuserdata/neddington.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..5fff278 Binary files /dev/null and b/ProIPhone_Ch07_SharingDataBetweenStructures.xcodeproj/project.xcworkspace/xcuserdata/neddington.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/ProIPhone_Ch07_SharingDataBetweenStructures.xcodeproj/xcuserdata/neddington.xcuserdatad/xcschemes/xcschememanagement.plist b/ProIPhone_Ch07_SharingDataBetweenStructures.xcodeproj/xcuserdata/neddington.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..fe73645 --- /dev/null +++ b/ProIPhone_Ch07_SharingDataBetweenStructures.xcodeproj/xcuserdata/neddington.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + ProIPhone_Ch07_SharingDataBetweenStructures.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/ProIPhone_Ch07_SharingDataBetweenStructures/ContentView.swift b/ProIPhone_Ch07_SharingDataBetweenStructures/ContentView.swift index 47f8271..3b25114 100644 --- a/ProIPhone_Ch07_SharingDataBetweenStructures/ContentView.swift +++ b/ProIPhone_Ch07_SharingDataBetweenStructures/ContentView.swift @@ -1,15 +1,10 @@ -// -// ContentView.swift -// ProIPhone_Ch07_SharingDataBetweenStructures -// -// Created by Mike Panitz on 9/26/23. -// - -import SwiftUI - import SwiftUI struct ContentView: View { + @State private var isDarkMode = false + @State private var student = Student(firstName: "John", lastName: "Doe") + @State private var course = Course(year: "2023", quarter: "Q1", area: "IT-MOB", courseNumber: "101", courseTitle: "Introduction to Programming") + var body: some View { TabView { RandomBackgroundColor() @@ -26,13 +21,15 @@ struct ContentView: View { .tabItem { Image(systemName: "3.circle") } - EnvironmentObjectView() + + // New View with Dark Mode Toggle and Student & Course Information + DarkModeAndDataView(isDarkMode: $isDarkMode, student: $student, course: $course) .tabItem { Image(systemName: "4.circle") } } .tabViewStyle(DefaultTabViewStyle()) - + .environment(\.colorScheme, isDarkMode ? .dark : .light) } } @@ -41,3 +38,67 @@ struct ContentView_Previews: PreviewProvider { ContentView() } } + +struct Student { + var firstName: String + var lastName: String +} + +struct Course { + var year: String + var quarter: String + var area: String + var courseNumber: String + var courseTitle: String +} + +struct DarkModeAndDataView: View { + @Binding var isDarkMode: Bool + @Binding var student: Student + @Binding var course: Course + + var body: some View { + VStack { + Toggle("Dark Mode", isOn: $isDarkMode) + .padding() + + Text("Student Information:") + .font(.headline) + + // Subcomponent for editing student information + StudentInfoView(student: $student) + + Text("Course Information:") + .font(.headline) + + // Subcomponent for editing course information + CourseInfoView(course: $course) + } + .padding() + } +} + +struct StudentInfoView: View { + @Binding var student: Student + + var body: some View { + VStack { + TextField("First Name", text: $student.firstName) + TextField("Last Name", text: $student.lastName) + } + } +} + +struct CourseInfoView: View { + @Binding var course: Course + + var body: some View { + VStack { + TextField("Year", text: $course.year) + TextField("Quarter", text: $course.quarter) + TextField("Area", text: $course.area) + TextField("Course Number", text: $course.courseNumber) + TextField("Course Title", text: $course.courseTitle) + } + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..7580262 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# Pro-IPhone-Ch07-SharingDataBetweenStructures