快速申请。我声明了一个主题类,包括以下内容:
class Theme {
enum Font {
static let header1 = UIFont(name: "IBM Plex Sans Bold", size: 32)!
static let header2 = UIFont(name: "IBM Plex Sans Bold", size: 20)! // Crash
static let pickerTitleFont = UIFont(name: "IBM Plex Sans Bold", size: 17)!
static let navBarFont = UIFont(name: "IBM Plex Sans Bold", size: 28)! // Crash
}
}
在appDelegate中,我有一个设置导航栏外观代理的例程,
let appearance = UINavigationBarAppearance()
appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white,
NSAttributedString.Key.font: Theme.Font.navBarFont]
有时(很少),当运行这个应用程序时,会发生崩溃。
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x0000000104d5a7c0
Termination Reason: SIGNAL 5 Trace/BPT trap: 5
Terminating Process: exc handler [19751]
Triggered by Thread: 0
Kernel Triage:
VM - pmap_enter retried due to resource shortage
VM - pmap_enter retried due to resource shortage
VM - pmap_enter retried due to resource shortage
VM - pmap_enter retried due to resource shortage
VM - pmap_enter retried due to resource shortage
Thread 0 name:
Thread 0 Crashed:
0 --- 0x0000000104d5a7c0 one-time initialization function for pickerTitleFont + 140
1 --- 0x0000000104d5a7a4 one-time initialization function for pickerTitleFont + 112
2 libdispatch.dylib 0x00000001b8550f88 _dispatch_client_callout + 20 (object.m:560)
3 libdispatch.dylib 0x00000001b85527d4 _dispatch_once_callout + 32 (once.c:52)
4 --- 0x0000000104d77104 Theme.Font.navBarFont.unsafeMutableAddressor + 20 (Theme.swift:75)
5 --- 0x0000000104d77104 AppDelegate.setupNavigationController(root:) + 1188 (AppDelegate.swift:152)
这次崩溃怎么会发生?它只是访问一个静态定义的变量。 崩溃没有明确说明崩溃发生的原因。
很奇怪,崩溃似乎是由访问
Font.navBarFont
引起的,但是在堆栈跟踪的较低位置它说它是pickerTitleFont
.
访问
header2
字体在视图中的标签上设置字体时也会发生此崩溃。