I’m try to implement a camera using AVFoundation.
When I call function
func capturePhoto(with settings: AVCapturePhotoSettings = AVCapturePhotoSettings()) {
print("got")
output.capturePhoto(with: settings, delegate: delegate!)
}
I will got the error
Fatal error: Unexpectedly found nil while unwrapping an Optional value
Here is the basic logic of my project.
Basically, I call the camera in the cameraView().
The HomeView() can navigate to the NewEmplyInfo(). And the NewEmplyInfo() can navigate to the cameraView().
(so HomeView() > NewEmplyInfo() > cameraView())
If I call NewEmplyInfo() directly just like the code I provide, I will not got the Fatal error.
But if I call the HomeView() then navigate to the NewEmplyInfo(), I will got the error.
@main
struct GroupClockApp: SwiftUI.App {
@StateObject var mainVM = GroupClock.shared
var body: some Scene {
WindowGroup {
NavigationView{
if mainVM.isUserLogin{
// HomeView()
NewEmplyInfo()
}else{
Login()
}
}
}
}
}
And Here is my HomeView(), even I comment everything, I still got the error.
import SwiftUI
struct HomeView: View {
var body: some View {
ZStack {
VStack {
NavigationLink{
NewEmplyInfo()
}label: {
Image(systemName: "plus.circle.fill")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 70, height: 70)
.foregroundColor(Color("GCColor"))
}
}
}
.padding()
.navigationTitle("")
.navigationBarBackButtonHidden(true)
.navigationBarHidden(true)
}
}
Yuwenqian Chen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.