Does embedding a Table inside a DisclosureGroup not work? If I uncomment the DisclosureGroup in the code below, the table doesn't display. Is there anything that I can do to make it work?
import SwiftUI
import PlaygroundSupport
class Foo: Identifiable {
let id: Int
let num: Double
init(id: Int, num: Double) {
self.id = id
self.num = num
}
}
typealias FooArray = [Foo]
struct ContentView: View {
@State var foos: FooArray = [
Foo(id: 1, num:0.0 ),
Foo(id: 2, num:0.1 ),
Foo(id: 3, num:0.2 ),
Foo(id: 4, num:0.3 )
]
@State private var revealFoos = true
var body: some View {
VStack {
Text("Foo")
.font(.title)
.bold()
Divider()
//DisclosureGroup("Foos", isExpanded: $revealFoos) {
FooTable(foos: foos)
//}
Spacer()
}
}
}
struct FooTable : View {
var foos: FooArray
@State private var sortOrder = [KeyPathComparator(\Foo.id, order: .reverse)]
var body: some View {
VStack {
Table(foos, sortOrder: $sortOrder) {
TableColumn("ID", value: \.id) { value in
Text(value.id.description)
}
TableColumn("Number", value: \.num) { value in
Text(value.num.description)
.frame(maxWidth: .infinity, alignment: .trailing)
}
}
}
}
}
PlaygroundPage.current.setLiveView(ContentView())
Post
Replies
Boosts
Views
Activity
Just upgraded to Sonoma and Xcode 15. When I try debugging my SwiftUI app, an assertion fires in AppKit (see below) on app start. I cleaned and tried debugging again and still get the same assertion. I also tried commenting out the app's toolbar but still got the same assertion. The same code worked before upgrading. Ideas?
*** Assertion failure in -[NSWindowSectionController registerSeparator:], NSWindowSectionController.m:529
An uncaught exception was raised
Cannot register more than one NSTrackingSeparatorToolbarItem that tracks the same divider
(
0 CoreFoundation 0x0000000185f3c8c0 __exceptionPreprocess + 176
1 libobjc.A.dylib 0x0000000185a35eb4 objc_exception_throw + 60
2 Foundation 0x000000018708318c -[NSCalendarDate initWithCoder:] + 0
3 AppKit 0x000000018a219cb8 -[NSWindowSectionController registerSeparator:] + 304
4 AppKit 0x000000018975952c -[NSToolbar _newItemFromItemIdentifier:propertyListRepresentation:requireImmediateLoad:willBeInsertedIntoToolbar:] + 384
5 AppKit 0x000000018975b2f4 -[NSToolbar _loadAllPlaceholderItems] + 292
6 AppKit 0x000000018976995c -[NSToolbar items] + 36
7 AppKit 0x0000000189769484 -[NSToolbarView _syncItemSet] + 84
8 AppKit 0x000000018a0efea8 -[NSToolbarView _syncItemSetAndUpdateItemViewersWithSEL:setNeedsModeConfiguration:setNeedsDisplay:updateKeyLoop:] + 48
9 AppKit 0x000000018975ace8 -[NSToolbarView setToolbar:] + 280
10 AppKit 0x000000018a0ee330 +[NSToolbarView newViewForToolbar:inWindow:] + 88
11 AppKit 0x000000018975a090 -[NSToolbar _loadViewIfNecessary] + 108
12 AppKit 0x0000000189759fc0 -[NSToolbar _windowWillShowToolbar] + 68
13 AppKit 0x0000000189759f08 -[NSWindow _showToolbar:animate:] + 128
14 AppKit 0x0000000189759e18 -[NSToolbar _show:animate:] + 92
15 AppKit 0x0000000189759d84 -[NSToolbar _toggleShown:animate:] + 88
16 AppKit 0x0000000189756f2c -[NSWindow setToolbar:] + 396
17 SwiftUI 0x00000001b14a73c4 OUTLINED_FUNCTION_0 + 78340
18 SwiftUI 0x00000001b14a65c8 OUTLINED_FUNCTION_0 + 74760
19 SwiftUI 0x00000001b14a6360 OUTLINED_FUNCTION_0 + 74144
20 SwiftUI 0x00000001b14a5a6c OUTLINED_FUNCTION_0 + 71852
21 SwiftUI 0x00000001b139f294 OUTLINED_FUNCTION_16 + 66792
22 SwiftUI 0x00000001b139f480 OUTLINED_FUNCTION_16 + 67284
23 AppKit 0x00000001896b4ae0 -[NSView _setWindow:] + 1788
24 AppKit 0x00000001896bc1cc -[NSView addSubview:] + 212
25 AppKit 0x00000001896c1ca0 -[NSFrameView addSubview:] + 52
26 AppKit 0x00000001896c1c54 -[NSThemeFrame addSubview:] + 452
27 AppKit 0x00000001896c1678 -[NSView addSubview:positioned:relativeTo:] + 372
28 AppKit 0x00000001896c1480 -[NSThemeFrame addSubview:positioned:relativeTo:] + 52
29 AppKit 0x00000001896c1434 -[NSThemeFrame _addKnownSubview:positioned:relativeTo:] + 44
30 AppKit 0x00000001896dbcf0 -[NSWindow setContentView:] + 292
31 AppKit 0x00000001898719c4 -[NSWindow _contentViewControllerChanged] + 364
32 AppKit 0x00000001896e2dc4 NSPerformVisuallyAtomicChange + 108
33 AppKit 0x00000001898717e4 -[NSWindow setContentViewController:] + 132
34 SwiftUI 0x00000001b14a2628 OUTLINED_FUNCTION_0 + 58472
35 SwiftUI 0x00000001b0d80cc0 OUTLINED_FUNCTION_29 + 9656
36 SwiftUI 0x00000001b0d81580 OUTLINED_FUNCTION_29 + 11896
37 SwiftUI 0x00000001b10b7f58 OUTLINED_FUNCTION_15 + 1044
38 SwiftUI 0x00000001b149d434 OUTLINED_FUNCTION_0 + 37492
39 SwiftUI 0x00000001b1499638 OUTLINED_FUNCTION_0 + 21624
40 SwiftUI 0x00000001b14983e4 OUTLINED_FUNCTION_0 + 16932
41 SwiftUI 0x00000001b1bc4624 OUTLINED_FUNCTION_93 + 3084
42 SwiftUI 0x00000001b1bc4960 OUTLINED_FUNCTION_93 + 3912
43 CoreFoundation 0x0000000185ebc780 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 148
44 CoreFoundation 0x0000000185f509a8 ___CFXRegistrationPost_block_invoke + 88
45 CoreFoundation 0x0000000185f508f0 _CFXRegistrationPost + 440
46 CoreFoundation 0x0000000185e8b434 _CFXNotificationPost + 764
47 Foundation 0x0000000186f7cc74 -[NSNotificationCenter postNotificationName:object:userInfo:] + 88
48 AppKit 0x00000001896a8960 -[NSApplication _postDidFinishNotification] + 284
49 AppKit 0x00000001896a8710 -[NSApplication _sendFinishLaunchingNotification] + 172
50 AppKit 0x00000001896a6c58 -[NSApplication(NSAppleEventHandling) _handleAEOpenEvent:] + 504
51 AppKit 0x00000001896a6854 -[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:] + 492
52 Foundation 0x0000000186fa5194 -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 316
53 Foundation 0x0000000186fa4f88 _NSAppleEventManagerGenericHandler + 80
54 AE 0x000000018cdeed8c _AppleEventsCheckInAppWithBlock + 13808
55 AE 0x000000018cdee6b4 _AppleEventsCheckInAppWithBlock + 12056
...
)
I'm running into a problem with using a DisclosureGroup on the Mac using Xcode 15/Sonoma 14.0. In the code below, if I set useDisclosureGroup to TRUE then the window in which SomeDetail is embedded will grow in vertical size and have its minimum vertical size changed to the new height of the window (so that it can't be shrunk vertically). If I set useDisclosureGroup to FALSE then everything works normally. The problem seems to be triggered by the lines demarcated by BUG/ENDBUG. If those lines are replaced by a simple Text view then the problem doesn't manifest.
Thoughts?
@ObservedObject var foo: Foo
@State private var now: Date? = Date.now
@State private var isSummaryExpanded: Bool = true
private let useDisclosureGroup = false
var body: some View {
VStack(alignment: .leading) {
if useDisclosureGroup {
DisclosureGroup("Summary", isExpanded: $isSummaryExpanded) {
HStack {
VStack(alignment: .leading) {
// BUG?
if let latestDate = now {
Text("Latest update: \(latestDate.description)")
} else {
Text("Latest update: --")
}
// ENDBUG
Text("placeholder")
}
Spacer()
}
}
}
else {
Section {
HStack {
VStack(alignment: .leading) {
if let latestDate = now {
Text("Latest update: \(latestDate.description)")
} else {
Text("Latest update: --")
}
Text("placeholder")
}
Spacer()
}
}
}
Spacer()
}
}
}
Running into a problem on macOS 14.0/SwiftUI. In the code below, the first Section(isExpanded:) component works (expands) while the second doesn't. The one that works is the one where the Bool controlling expansion is referenced by another component. The one that doesn't is where the Bool controlling expansion isn't referenced.
Anybody know what's happening in this case or have a workaround (other than the one used in this example)?
@ObservedObject var foo: Foo
@State private var isExpanded_1 = true
@State private var isExpanded_2 = true
var body: some View {
VStack {
// This section's expansion works because isExpanded_1 is referenced by another component (Text).
Text("isSummaryExpanded = \(isExpanded_1.description)")
Section(isExpanded: $isExpanded_1) {
Text("Working section")
}
header: {
SummaryHeader(isSummaryExpanded: $isExpanded_1)
}
// This section's expansion doesn't work because isExpanded_2 isn't referenced anywhere else.
Section(isExpanded: $isExpanded_2) {
Text("Broken section")
}
header: {
SummaryHeader(isSummaryExpanded: $isExpanded_2)
}
Spacer()
}
}
}
In the olden days, if one filed a code-level support ticket and the issue turned out to be a bug in Apple software, one wouldn't necessarily get charged for the support request. Is this still the case? What is the determination for whether a ticket is expended or not – or does it come down to the support engineer's discretion?
Can anyone here explain how the VSplitView container is laid out by SwiftUI on macOS? I had a view that was using a VStack container. When I replaced it with a VSplitView container, the view ended up present in a narrow vertical strip inside its containing view.
Here's what it looks like with a VStack:
Here's what it looks like with a VSplitView:
More generally, are there any good sources for understanding the inner workings of SwiftUI components? I know about Chris Eidhof's book but it seems limited as to how individual components work.