我有一个ProfileRegistration struct ,它只是一个基本模型.我没有任何问题.然而,只要我向模型中添加一个新属性,应用程序就会在运行时崩溃,只要它在代码中的任何地方被访问.

// Causes app to crash
struct ProfileRegistration: Codable {
    let resourceNumber: String?
    let nickName: String?
    let firstName: String?
    let initials: String?
    let name: String?
    let lastName: String?
    let gender: Gender?
    let birthdate: String?
    let nationality: String?
    let phoneNumber: String?
    let email: String?
    
    let insuranceNumber: String?
    let employmentDate: String?
    let username: String?
    
    var worksteadLocations: [WorksteadLocation] = []
    var coworkerInformations: [CoworkerInformation] = []
    
    var worksteadLocation: WorksteadLocation? {
        worksteadLocations.first
    }
    
    var jobCoachFirstName: String? {
        coworkerInformations.first?.firstName
    }
}
// Doesn't cause app to crash
struct ProfileRegistration: Codable {
    let resourceNumber: String?
    let nickName: String? 
    let firstName: String?
    let initials: String?
    // let name: String?
    let lastName: String?
    let gender: Gender?
    let birthdate: String?
    let nationality: String?
    let phoneNumber: String?
    let email: String?
    
    let insuranceNumber: String?
    let employmentDate: String?
    let username: String?
    
    var worksteadLocations: [WorksteadLocation] = []
    var coworkerInformations: [CoworkerInformation] = []
    
    var worksteadLocation: WorksteadLocation? {
        worksteadLocations.first
    }
    
    var jobCoachFirstName: String? {
        coworkerInformations.first?.firstName
    }
}

我得到错误:

Thread 10: EXC_BAD_ACCESS (code=EXC_I386_GPFLT)

就在堆栈中的错误上方,我看到了

async function pointer to reabstraction thunk helper from @escaping @callee_guaranteed @Sendable @async () -> (@owned Workstead.ProfileRegistration, @error @owned Swift.Error) to @escaping @callee_guaranteed @async () -> (@out Workstead.ProfileRegistration, @error @owned Swift.Error)

完整堆栈:

Workstead`partial apply for thunk for @escaping @callee_guaranteed @Sendable @async () -> (@owned ProfileRegistration, @error @owned Error):
    0x102cc10f0 <+0>:   orq    0x9d5409(%rip), %rbp      ; (void *)0x1000000000000000
    0x102cc10f7 <+7>:   pushq  %rbp
    0x102cc10f8 <+8>:   pushq  %r14
    0x102cc10fa <+10>:  leaq   0x8(%rsp), %rbp
    0x102cc10ff <+15>:  subq   $0x38, %rsp
    0x102cc1103 <+19>:  movq   %r14, -0x10(%rbp)
    0x102cc1107 <+23>:  movq   %rdi, -0x28(%rbp)
    0x102cc110b <+27>:  xorl   %eax, %eax
    0x102cc110d <+29>:  movl   %eax, %edi
    0x102cc110f <+31>:  callq  0x102ccf350               ; ___lldb_unnamed_symbol350$$Workstead
    0x102cc1114 <+36>:  movq   %r14, 0x18(%r14)
    0x102cc1118 <+40>:  movq   0x10(%r13), %rax
    0x102cc111c <+44>:  movq   %rax, -0x20(%rbp)
    0x102cc1120 <+48>:  movq   0x18(%r13), %rax
    0x102cc1124 <+52>:  movq   %rax, -0x18(%rbp)
    0x102cc1128 <+56>:  movl   0xa52fd6(%rip), %eax      ; async function pointer to reabstraction thunk helper from @escaping @callee_guaranteed @Sendable @async () -> (@owned Workstead.ProfileRegistration, @error @owned Swift.Error) to @escaping @callee_guaranteed @async () -> (@out Workstead.ProfileRegistration, @error @owned Swift.Error) + 4
    0x102cc112e <+62>:  movl   %eax, %edi
    0x102cc1130 <+64>:  callq  0x10354a1de               ; symbol stub for: swift_task_alloc
->  0x102cc1135 <+69>:  movq   -0x28(%rbp), %rdi
    0x102cc1139 <+73>:  movq   -0x20(%rbp), %rsi
    0x102cc113d <+77>:  movq   -0x18(%rbp), %rdx
    0x102cc1141 <+81>:  movq   %rax, %r14
    0x102cc1144 <+84>:  movq   -0x10(%rbp), %rax
    0x102cc1148 <+88>:  movq   %r14, 0x20(%rax)
    0x102cc114c <+92>:  movq   0x18(%rax), %rax
    0x102cc1150 <+96>:  movq   %rax, (%r14)
    0x102cc1153 <+99>:  leaq   0x26(%rip), %rax          ; (1) await resume partial function for partial apply forwarder for reabstraction thunk helper from @escaping @callee_guaranteed @Sendable @async () -> (@owned Workstead.ProfileRegistration, @error @owned Swift.Error) to @escaping @callee_guaranteed @async () -> (@out Workstead.ProfileRegistration, @error @owned Swift.Error) at <compiler-generated>
    0x102cc115a <+106>: movq   %rax, 0x8(%r14)
    0x102cc115e <+110>: addq   $0x30, %rsp
    0x102cc1162 <+114>: addq   $0x10, %rsp
    0x102cc1166 <+118>: popq   %rbp
    0x102cc1167 <+119>: btrq   $0x3c, %rbp
    0x102cc116c <+124>: jmp    0x102cc0f60               ; reabstraction thunk helper from @escaping @callee_guaranteed @Sendable @async () -> (@owned Workstead.ProfileRegistration, @error @owned Swift.Error) to @escaping @callee_guaranteed @async () -> (@out Workstead.ProfileRegistration, @error @owned Swift.Error) at <compiler-generated>

我向 struct 添加什么属性似乎无关紧要,当我添加一个属性时,它总是崩溃.当我删除属性时,它不会崩溃.

我使用的是Xcode版本13.3.1(13E500a),运行在iOS 15.4上,在多个设备上进行了测试

Xcode error screenshot

推荐答案

我也有同样的错误.

async let req1 = await someManager.fetch()
async let req2 = await someManager.get(id: uid)

let (result1, result2) = await (req1, req2)

我将其拆分以同步网络请求:

let result1 = await someManager.fetch()
let result2 = await someManager.get(id: uid)

它开始起作用了.

我认为iOS方面存在一些问题.

Ios相关问答推荐

无法在fastlane和github操作中从react-native 应用程序构建ios

我想在expo 中使用useSafeAreaInsets来获取paddingbottom,但我得到了一个错误

在iOS 17脉冲符号效果不起作用的情况下制作UIBarButtonItem动画(没有UIImageView)

在某些情况下,UIHostingController在自动调整时不能调整大小

检测touch 并忽略其他手势SWIFT SceneKit

Xcode 15阻止我的应用程序运行:由于实时模式录制的高比率,丢失了1条日志(log)/路标消息?

Swift Combine和iOS版本限制?

SwiftUI中的Tap手势无法识别视图上的偏移变化

ITMS-90725 无用的错误信息,因为它自相矛盾,苹果上传

占位符文本未显示在 TextEditor 上

iOS 16 堆栈视图中按钮的奇怪动画

SwiftUI 切换语句

SwiftUI DatePicker 格式在每个设备上都不一样,如何让它总是显示相同的 Select 版本?

如何在不支持并发的自动关闭中修复'async'调用?

iOS,Swift 5,AppDelegate open url / .onOpenUrl - 如何找到调用我的自定义方案的调用应用程序

无法同时满足约束 - 没有适当的约束

iPhone iOS 无法正确显示 box-shadow

不变违规:应用程序 AwesomeProject 尚未注册使用静态 jsbundle 为 iOS 设备构建时

闭包不能隐式捕获变异的 self 参数

如何在 Swift 中更改按钮标题对齐方式?