Posts

Post not yet marked as solved
8 Replies
Same issue here. Several days ago, it works, but now, only macOS could not show the Swift Actors and Swift Tasks.
Post marked as solved
5 Replies
SwiftUI 5 (iOS 17, macOS 14) MyEqualWidthHStack { Button { Task { await update() } } label: { Text("update") .frame(maxWidth: .infinity) } .border(.yellow) Button { Task { await sync() } } label: { Text("sync") .frame(maxWidth: .infinity) } .border(.yellow) }
Post not yet marked as solved
2 Replies
MyEqualWidthHStack { Button { Task { await update() } } label: { Text("update") .frame(maxWidth: .infinity) } .border(.yellow) Button { Task { await sync() } } label: { Text("sync") .frame(maxWidth: .infinity) } .border(.yellow) } struct MyEqualWidthHStack: Layout { func sizeThatFits( proposal: ProposedViewSize, subviews: Subviews, cache: inout Void ) -> CGSize { // Return a size. guard !subviews.isEmpty else { return .zero } let maxSize = maxSize(subviews: subviews) let spacing = spacing(subviews: subviews) let totalSpacing = spacing.reduce(0) { $0 + $1 } return CGSize( width: maxSize.width * CGFloat(subviews.count) + totalSpacing, height: maxSize.height) } func placeSubviews( in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout Void ) { // Place child views. guard !subviews.isEmpty else { return } let maxSize = maxSize(subviews: subviews) let spacing = spacing(subviews: subviews) let placementProposal = ProposedViewSize(width: maxSize.width, height: maxSize.height) var x = bounds.minX + maxSize.width / 2 for index in subviews.indices { subviews[index].place( at: CGPoint(x: x, y: bounds.midY), anchor: .center, proposal: placementProposal) x += maxSize.width + spacing[index] } } private func maxSize(subviews: Subviews) -> CGSize { let subviewSizes = subviews.map { $0.sizeThatFits(.unspecified) } let maxSize: CGSize = subviewSizes.reduce(.zero) { currentMax, subviewSize in CGSize( width: max(currentMax.width, subviewSize.width), height: max(currentMax.height, subviewSize.height)) } return maxSize } private func spacing(subviews: Subviews) -> [CGFloat] { subviews.indices.map { index in guard index < subviews.count - 1 else { return 0 } return subviews[index].spacing.distance( to: subviews[index + 1].spacing, along: .horizontal) } } } https://developer.apple.com/documentation/swiftui/composing_custom_layouts_with_swiftui
Post marked as solved
2 Replies
It is the right result. The tap area is larger than the Button border. If you want to adjust the tap area, you should adjust the code. For example, use Rectangle with .onTapGesture
Post not yet marked as solved
2 Replies
This seems to be a certain trust or initial issue. When a new iCloud container id appears, the device need some steps to trust the new container. I must use a previous trused app to link the new container to the new device (trusted means the app can access the iCloud Documents).For example, "ShapeEdit“ has an icloud container "com.example.ShapeEdit", it could access its container without problem.A new app called "MyApp" wants to use new iCloud container id "com.mycompany.MyApp", but it always fails recently.Change "ShapeEdit“ to use the new icloud container "com.mycompany.MyApp" will let "MyApp" access it, and the device trust new the iCloud container.If you update the bundle id of "ShapeEdit“, and use a new icloud container "com.example.ShapeEdit2", the new ShapeEdit will also fail on the same device.So this is not the developer's code problem. It should be some iCloud Container initial step issue on iOS devices.