Skip to content

Commit e654f29

Browse files
committed
Add support for CDGenerationOptions in RuntimeObjectDetail
Improve error handling when underlying runtime object is not found in RuntimeObjectDetail
1 parent 48efa43 commit e654f29

File tree

2 files changed

+58
-22
lines changed

2 files changed

+58
-22
lines changed

ClassDumpRuntime

Submodule ClassDumpRuntime updated 47 files

HeaderViewer/RuntimeObjectDetail.swift

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,66 @@ import ClassDump
1111
struct RuntimeObjectDetail: View {
1212
let type: RuntimeObjectType
1313

14-
private var semanticString: CDSemanticString {
15-
switch type {
16-
case .class(let named):
17-
CDClassModel(with: NSClassFromString(named))
18-
.semanticLines(withComments: false, synthesizeStrip: true)
19-
case .protocol(let named):
20-
CDProtocolModel(with: NSProtocolFromString(named))
21-
.semanticLines(withComments: false, synthesizeStrip: true)
22-
}
14+
@State private var stripProtocolConformance: Bool = false
15+
@State private var stripOverrides: Bool = false
16+
@State private var stripDuplicates: Bool = true
17+
@State private var stripSynthesized: Bool = true
18+
@State private var addSymbolImageComments: Bool = false
19+
20+
private var generationOptions: CDGenerationOptions {
21+
let options: CDGenerationOptions = .init()
22+
options.stripProtocolConformance = stripProtocolConformance
23+
options.stripOverrides = stripOverrides
24+
options.stripDuplicates = stripDuplicates
25+
options.stripSynthesized = stripSynthesized
26+
options.stripCtorMethod = true
27+
options.stripDtorMethod = true
28+
options.addSymbolImageComments = addSymbolImageComments
29+
return options
2330
}
2431

2532
var body: some View {
26-
#if os(iOS) || os(watchOS)
27-
SemanticStringView(semanticString)
28-
.navigationTitle(type.name)
29-
.navigationBarTitleDisplayMode(.inline)
30-
#elseif os(visionOS)
31-
SemanticStringView(semanticString)
32-
.background(.ultraThickMaterial)
33-
.navigationTitle(type.name)
34-
.navigationBarTitleDisplayMode(.inline)
35-
#else
36-
SemanticStringView(semanticString)
37-
.navigationTitle(type.name)
33+
Group {
34+
switch type {
35+
case .class(let name):
36+
if let cls = NSClassFromString(name) {
37+
let semanticString: CDSemanticString = CDClassModel(with: cls)
38+
.semanticLines(with: generationOptions)
39+
SemanticStringView(semanticString)
40+
} else {
41+
Text("No class named \(Text(name).font(.callout.monospaced())) found")
42+
.scenePadding()
43+
}
44+
case .protocol(let name):
45+
if let prtcl = NSProtocolFromString(name) {
46+
let semanticString: CDSemanticString = CDProtocolModel(with: prtcl)
47+
.semanticLines(with: generationOptions)
48+
SemanticStringView(semanticString)
49+
} else {
50+
Text("No protocol named \(Text(name).font(.callout.monospaced())) found")
51+
.scenePadding()
52+
}
53+
}
54+
}
55+
.navigationTitle(type.name)
56+
.toolbar {
57+
ToolbarItem {
58+
Menu {
59+
Toggle("Strip protocol conformance", isOn: $stripProtocolConformance)
60+
Toggle("Strip overrides", isOn: $stripOverrides)
61+
Toggle("Strip duplicates", isOn: $stripDuplicates)
62+
Toggle("Strip synthesized", isOn: $stripSynthesized)
63+
Toggle("Add symbol comments", isOn: $addSymbolImageComments)
64+
} label: {
65+
Label("Generation options", systemImage: "ellipsis.curlybraces")
66+
}
67+
}
68+
}
69+
#if os(iOS) || os(watchOS) || os(visionOS)
70+
.navigationBarTitleDisplayMode(.inline)
71+
#endif
72+
#if os(visionOS)
73+
.background(.ultraThickMaterial)
3874
#endif
3975
}
4076
}

0 commit comments

Comments
 (0)