swift 即使模拟器正在工作并且构建成功,Xcode预览仍然意外退出,我正在使用firebase ios sdk依赖项

cx6n0qe3  于 2022-12-10  发布在  Swift
关注(0)|答案(1)|浏览(129)

预览不断粉碎,即使我没有看到任何错误,在我的代码和建设是成功的。当我选择重新打开它只是退出再次我有一个m1 mba和xcode版本是版本14.1(14B47b).什么可能是问题

以下是代码

`

//
//  ContentView.swift
//  ChatApp

import SwiftUI
import Firebase

struct ContentView: View {
    @State var isUserLoggedIn = false
    @State var email = ""
    @State var password = ""
    @State var signUpMessage = ""
    @State var loginMessage = ""
    
    init() {
        FirebaseApp.configure()
    }
    
    
    var body: some View {
        NavigationStack{
            ScrollView{
                Picker("Login", selection: $isUserLoggedIn) {
                    Text("Login")
                        .tag(true)
                    Text("Sign up")
                        .tag(false)
                }
                .padding()
                .pickerStyle(.segmented)
                
                // profile picker
                if isUserLoggedIn == false{
                    Button {
                        //
                    } label: {
                        Image(systemName: "person.fill")
                            .foregroundColor(Color(.systemBlue))
                            .font(.system(size: 50))
                            .padding()
                    }
                }

                // user input fields
                VStack(spacing: 15){
                    TextField("Email", text: $email)
                        .keyboardType(.emailAddress)
                        .textInputAutocapitalization(.never)
                    SecureField("Password", text: $password)
                }
                .padding()
                .textFieldStyle(.roundedBorder)
                
                
                // login / sign up button
                VStack{
                    Button {
                        // handle user login or sign up
                        handleUserAction()
                    } label: {
                        HStack{
                            Spacer()
                            Text(isUserLoggedIn ? "Login" : "Sign up")
                                .foregroundColor(.white)
                                .padding()
                                .font(.system(size: 20))
                                .fontWeight(.semibold)
                            Spacer()
                        }
                        .background(Color(.systemBlue).opacity(0.8))
                        .padding()
                    }
                    
                    // display status message
                    VStack{
                        Text(isUserLoggedIn ? loginMessage : signUpMessage)
                        Text(signUpMessage)
                    }
                        .multilineTextAlignment(.center)
                        .font(.caption)
                        .fontWeight(.semibold)
                        .foregroundColor(.red)

                }
                
            }
            .navigationTitle(isUserLoggedIn ? "Login" : "Create account")
        }
    }
    
    func handleUserAction(){
        
        if isUserLoggedIn{
            // login user
            loginUser()
            self.loginMessage = "login sucessful"
        }else{
            // register user
           registerUser()
            self.signUpMessage = "Sign up succcessful"
        }
    }
    
    // register user
    func registerUser(){
        Auth.auth().createUser(withEmail: email, password: password) { result, error in
            if let error = error{
                self.signUpMessage = "Failed to create user\(error.localizedDescription)"
                return
            }
            self.signUpMessage = "User creation successful \(result?.user.uid ?? "")"
        }
    }
    
    //  login user
    func loginUser(){
        Auth.auth().signIn(withEmail: email, password: password) { result, err in
            if let err = err{
                self.loginMessage = "Failed to login user \(err)"
                return
            }
            self.loginMessage = "Login successful \(result?.user.uid ?? "")"
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

`

以下是预览报告

`

Translated Report (Full Report Below)

Incident Identifier: 90F4316A-96EF-4203-B49C-CF071AB776E7
CrashReporter Key:   4F7E4327-238B-DBA9-0BD0-3D28FAEF4F3E
Hardware Model:      MacBookAir10,1
Process:             ChatApp [17768]
Path:                /Users/USER/Library/Developer/Xcode/UserData/Previews/Simulator Devices/F8CD4B09-A5B6-4F40-A675-4F812E8909E1/data/Containers/Bundle/Application/7745454B-444D-4353-A900-983C4868CCB8/ChatApp.app/ChatApp
Identifier:          com.ChatApp
Version:             1.0 (1)
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd_sim [16905]
Coalition:           com.apple.CoreSimulator.SimDevice.F8CD4B09-A5B6-4F40-A675-4F812E8909E1 [16852]
Responsible Process: SimulatorTrampoline [3530]

Date/Time:           2022-12-07 14:16:35.0965 +0300
Launch Time:         2022-12-07 14:16:32.9144 +0300
OS Version:          macOS 13.0.1 (22A400)
Release Type:        User
Report Version:      104

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x0000000184abae1c
Termination Reason: SIGNAL 5 Trace/BPT trap: 5
Terminating Process: exc handler [17768]

Triggered by Thread:  0

Kernel Triage:
VM - pmap_enter retried due to resource shortage
VM - pmap_enter retried due to resource shortage

Thread 0 Crashed::  Dispatch queue: BSXPCCnx:com.apple.dt.xcode-previews.systemservices (BSCnx:client:com.apple.dt.uv.agent-preview-scene-service)
0   BoardServices                          0x184abae1c __79+[BSXPCServiceConnectionProxy invokeMethod:onTarget:withMessage:forConnection:]_block_invoke.68 + 292
1   BoardServices                          0x184abae1c __79+[BSXPCServiceConnectionProxy invokeMethod:onTarget:withMessage:forConnection:]_block_invoke.68 + 292
2   BoardServices                          0x184ab9800 +[BSXPCServiceConnectionProxy invokeMethod:onTarget:withMessage:forConnection:] + 5152
3   BoardServices                          0x184ac7238 __63-[BSXPCServiceConnectionEventHandler connection:handleMessage:]_block_invoke + 536
4   BoardServices                          0x184aeb188 BSXPCServiceConnectionExecuteCallOut + 232
5   BoardServices                          0x184ac6ed0 -[BSXPCServiceConnectionEventHandler connection:handleMessage:] + 148
6   BoardServices                          0x184aea710 -[BSXPCServiceConnection _connection_handleMessage:fromPeer:withHandoff:] + 512
7   libdispatch.dylib                      0x180133fa4 _dispatch_call_block_and_release + 24
8   libdispatch.dylib                      0x180135768 _dispatch_client_callout + 16
9   libdispatch.dylib                      0x18013d7f8 _dispatch_lane_serial_drain + 780
10  libdispatch.dylib                      0x18013e474 _dispatch_lane_invoke + 448
11  libdispatch.dylib                      0x180144e8c _dispatch_main_queue_drain + 824
12  libdispatch.dylib                      0x180144b44 _dispatch_main_queue_callback_4CF + 40
13  CoreFoundation                         0x180372cf4 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
14  CoreFoundation                         0x18036d3b0 __CFRunLoopRun + 1956
15  CoreFoundation                         0x18036c7f4 CFRunLoopRunSpecific + 584
16  GraphicsServices                       0x188faec98 GSEventRunModal + 160
17  UIKitCore                              0x1085fc5d4 -[UIApplication _run] + 868
18  UIKitCore                              0x1086005cc UIApplicationMain + 124
19  SwiftUI                                0x10c9fab18 0x10bab0000 + 16034584
20  SwiftUI                                0x10c9fa9c0 0x10bab0000 + 16034240
21  SwiftUI                                0x10c19e36c 0x10bab0000 + 7267180
22  ChatApp                                0x1000a70c8 static ChatAppApp.$main() + 40 (ChatAppApp.swift:10)
23  ChatApp                                0x1000a71b4 main + 12
24  dyld_sim                               0x106d19fa0 start_sim + 20
25  dyld                                   0x106ac5e50 start + 2544

Thread 1:
0   libsystem_pthread.dylib                0x1af2556b8 start_wqthread + 0

Thread 2:
0   libsystem_pthread.dylib                0x1af2556b8 start_wqthread + 0

Thread 3:
0   libsystem_pthread.dylib                0x1af2556b8 start_wqthread + 0

Thread 4:
0   libsystem_pthread.dylib                0x1af2556b8 start_wqthread + 0

Thread 5:: com.apple.uikit.eventfetch-thread
0   libsystem_kernel.dylib                 0x1af1fe30c mach_msg2_trap + 8
1   libsystem_kernel.dylib                 0x1af20f16c mach_msg2_internal + 76
2   libsystem_kernel.dylib                 0x1af20650c mach_msg_overwrite + 536
3   libsystem_kernel.dylib                 0x1af1fe67c mach_msg + 20
4   CoreFoundation                         0x180372a18 __CFRunLoopServiceMachPort + 156
5   CoreFoundation                         0x18036d08c __CFRunLoopRun + 1152
6   CoreFoundation                         0x18036c7f4 CFRunLoopRunSpecific + 584
7   Foundation                             0x180bcf0c8 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 208
8   Foundation                             0x180bcf2ec -[NSRunLoop(NSRunLoop) runUntilDate:] + 60
9   UIKitCore                              0x10869b6e0 -[UIEventFetcher threadMain] + 424
10  Foundation                             0x180bf4aac __NSThread__start__ + 704
11  libsystem_pthread.dylib                0x1af25a4e4 _pthread_start + 116
12  libsystem_pthread.dylib                0x1af2556cc thread_start + 8

Thread 6:
0   libsystem_pthread.dylib                0x1af2556b8 start_wqthread + 0

Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x000000014a866a18   x1: 0x0000000008000100   x2: 0x0000000000000001   x3: 0x0000000000000001
    x4: 0x00006000018c5ac0   x5: 0x0000000000000000   x6: 0x0000000000002a98   x7: 0x0000000000000000
    x8: 0x00000001b7a45000   x9: 0xf0591fef09e3009e  x10: 0x0000000ffffffff8  x11: 0x000000000000003f
   x12: 0x000000000000006b  x13: 0x000000014c0190a0  x14: 0x01000001b793b239  x15: 0x00000001b793b238
   x16: 0x0000000183352ed8  x17: 0x000000018034b05c  x18: 0x0000000000000000  x19: 0x000000016fd64118
   x20: 0x000000014a866a00  x21: 0x0000600003cf04c0  x22: 0x00006000029db180  x23: 0x00006000029c8e80
   x24: 0x0000000000000076  x25: 0x00006000032c9560  x26: 0x0000000000000000  x27: 0x00006000032caaf0
   x28: 0x0000000000000003   fp: 0x000000016fd640c0   lr: 0x0000000184abae1c
    sp: 0x000000016fd64030   pc: 0x0000000184abae1c cpsr: 0x60001000
   far: 0x000000014a86a408  esr: 0xf2000000 (Breakpoint) brk 0

Binary Images:
       0x184ab3000 -        0x184b05fff com.apple.BoardServices (1.0) <c3409b2b-aac8-3e71-b35d-71340ebd2740> /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/BoardServices.framework/BoardServices
       0x180132000 -        0x180178fff libdispatch.dylib (*) <2cd267ae-adf6-3f56-897a-04baff62b34f> /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/libdispatch.dylib
       0x1802ed000 -        0x180699fff com.apple.CoreFoundation (6.9) <b02805dc-7bce-3571-8eb6-ff671506488b> /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
       0x188fab000 -        0x188fb3fff com.apple.GraphicsServices (1.0) <66f66f45-e32d-348b-9833-1f04b12a4703> /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices
       0x107b94000 -        0x10923ffff com.apple.UIKitCore (1.0) <e9f0192a-4554-3c71-b825-c7a78cfdf7d4> /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore
       0x10bab0000 -        0x10d027fff com.apple.SwiftUI (4.1.17.100) <bd0565ad-87fa-3dc2-b25c-4d7f849557bc> /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/SwiftUI.framework/SwiftUI
       0x100098000 -        0x1015affff com.ChatApp (1.0) <17fc0747-cd39-374a-b9d5-8b907ffe50de> /Users/USER/Library/Developer/Xcode/UserData/Previews/Simulator Devices/F8CD4B09-A5B6-4F40-A675-4F812E8909E1/data/Containers/Bundle/Application/7745454B-444D-4353-A900-983C4868CCB8/ChatApp.app/ChatApp
       0x106d18000 -        0x106d67fff dyld_sim (*) <1772df31-9df3-36cc-a3c6-b34fd26bffe5> /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/dyld_sim
       0x106ac0000 -        0x106b4bfff dyld (*) <de46dd52-4994-3fd8-b4b4-e352a1a19354> /usr/lib/dyld
       0x1af253000 -        0x1af25fff3 libsystem_pthread.dylib (*) <030d2641-514f-373f-9688-582d9d3b369a> /usr/lib/system/libsystem_pthread.dylib
       0x1af1fd000 -        0x1af234fef libsystem_kernel.dylib (*) <99ef4d89-bf00-3860-a076-24f05834886c> /usr/lib/system/libsystem_kernel.dylib
       0x180710000 -        0x180fc4fff com.apple.Foundation (6.9) <532aae62-f6cf-3de2-8988-170389a83ad5> /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/Foundation.framework/Foundation

`
我试着清理构建,但它一直退出。我甚至试着重新启动xcode,但问题仍然存在。

flvlnr44

flvlnr441#

开始bij移除:

init() {
        FirebaseApp.configure()
    }

这应该在你的appnameApp中,它不是为视图设计的,而是为你的整个应用设计的。

相关问题