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

Session 6: Lifecycle of UIViewController #5

Merged
merged 4 commits into from
Feb 26, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions YumemiTraining.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
F072BB632B7F49F300A8E86F /* SizePreferenceKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = F072BB622B7F49F300A8E86F /* SizePreferenceKey.swift */; };
F072BB652B7F569200A8E86F /* Weather.swift in Sources */ = {isa = PBXBuildFile; fileRef = F072BB642B7F569200A8E86F /* Weather.swift */; };
F0AEFC312B85E2270090F669 /* TemperatureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0AEFC302B85E2270090F669 /* TemperatureView.swift */; };
F072BB6B2B7F848600A8E86F /* NewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F072BB6A2B7F848600A8E86F /* NewView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -32,6 +33,7 @@
F072BB622B7F49F300A8E86F /* SizePreferenceKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SizePreferenceKey.swift; sourceTree = "<group>"; };
F072BB642B7F569200A8E86F /* Weather.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Weather.swift; sourceTree = "<group>"; };
F0AEFC302B85E2270090F669 /* TemperatureView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemperatureView.swift; sourceTree = "<group>"; };
F072BB6A2B7F848600A8E86F /* NewView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -66,6 +68,7 @@
isa = PBXGroup;
children = (
F072BB492B7F09D400A8E86F /* YumemiTrainingApp.swift */,
F072BB6A2B7F848600A8E86F /* NewView.swift */,
F072BB4B2B7F09D400A8E86F /* ForecastView.swift */,
F0AEFC302B85E2270090F669 /* TemperatureView.swift */,
F072BB602B7F496500A8E86F /* View+.swift */,
Expand Down Expand Up @@ -167,6 +170,7 @@
F072BB5D2B7F2C9300A8E86F /* WeatherCondition.swift in Sources */,
F072BB5B2B7F2B9600A8E86F /* ForecastViewModel.swift in Sources */,
F072BB4C2B7F09D400A8E86F /* ForecastView.swift in Sources */,
F072BB6B2B7F848600A8E86F /* NewView.swift in Sources */,
F072BB4A2B7F09D400A8E86F /* YumemiTrainingApp.swift in Sources */,
F0AEFC312B85E2270090F669 /* TemperatureView.swift in Sources */,
F072BB632B7F49F300A8E86F /* SizePreferenceKey.swift in Sources */,
Expand Down
5 changes: 3 additions & 2 deletions YumemiTraining/ForecastView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import SwiftUI

struct ForecastView<ViewModel: ForecastViewModel>: View {
@Environment(\.dismiss) var dismiss
@StateObject var viewModel: ViewModel
@State private var buttonsSize: CGSize = .zero

Expand Down Expand Up @@ -37,7 +38,8 @@ struct ForecastView<ViewModel: ForecastViewModel>: View {

HStack(spacing: 0) {
Button {
// TODO: Close Action
// Close Action
self.dismiss()
} label: {
Text("Close")
}
Expand Down Expand Up @@ -78,7 +80,6 @@ struct ForecastView<ViewModel: ForecastViewModel>: View {
Text(message)
}
}

}
}

Expand Down
1 change: 0 additions & 1 deletion YumemiTraining/ForecastViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import YumemiWeather
@MainActor
protocol ForecastViewModel: ObservableObject {
var weather: Weather? { get }
var weatherCondition: WeatherCondition? { get }
var alertMessage: String? { get }
var isAlertPresented: Bool { get set }

Expand Down
31 changes: 31 additions & 0 deletions YumemiTraining/NewView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// NewView.swift
// YumemiTraining
//
// Created by 及川 寛太 on 2024/02/16.
//

import SwiftUI

struct NewView: View {
kantacky marked this conversation as resolved.
Show resolved Hide resolved
@State var isPresented: Bool = false

var body: some View {
EmptyView()
.onAppear {
self.isPresented = true
}
.fullScreenCover(isPresented: $isPresented) {
ForecastView(
viewModel: ForecastViewModelImpl()
)
.onDisappear {
self.isPresented = true
}
}
}
}

#Preview {
NewView()
}
2 changes: 1 addition & 1 deletion YumemiTraining/YumemiTrainingApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftUI
struct YumemiTrainingApp: App {
var body: some Scene {
WindowGroup {
ForecastView(viewModel: ForecastViewModelImpl())
NewView()
}
}
}