Post

Replies

Boosts

Views

Activity

How does SwiftUI update if objectWillChange fires *before* change
I'm wondering how SwiftUI updates work in connection with ObservableObjects. If a SwiftUI View depends on an `ObservableObject`, the object's `objectWillChange` publisher fires, and SwiftUI learns about the change, before the change happens. At this point, SwiftUI can't re-render a View, right? Because the new properties aren't there yet. So what does SwiftUI do? Does it schedule the change for later? That doesn't make sense either - how can it know when the object will be ready to be used in a new rendering of the UI? ~ Rob
3
0
5.4k
Feb ’22
Combining chars do not render right in some fonts
Here's a simple demo. I run it on macOS 12.1, compiled with Xcode 13.2. struct ContentView: View {     var body: some View {         VStack {             Text("ee")             Text("eé") Text("e\u{E9}") // "e with acute"             Text("ee\u{301}") // "combining acute"         }.font(.custom("Avenir", fixedSize: 18))          .padding(20)     } } In the 4rd one, the "e" is rendered in the wrong size/font. Screenshot: Other fonts do not have the problem. For example, "Avenir Next" and "Helvetica". Is there a way (in code) to tell which fonts can handle combining chars? Is this a bug? I notice the same thing happens when I use Core Text to draw the strings at a low level. So it's not just SwiftUI. In TextEdit, if have Avenir font, type "option-e" + "e" I get a nice letter. Maybe TextEdit is doing what Xcode did in the second line, and using the "e with acute" unicode character.
2
0
790
Feb ’22
Hierarchical List / OutlineGroup - can't change data?
Does anyone use the new hierarchical data List (ie, OutlineGroup) with a model where the tree data changes? I'm on Big Sur beta. I have code like this: List([treeRoot], children: \.children) { item in ... Say the treeRoot (observed object) gets a new child. The view tries to re-render and fails: 2020-09-21 ... [General] NSOutlineView error inserting child indexes <_NSCachedIndexSet: 0x600000760000>[number of indexes: 1 (in 1 ranges), indexes: (3)] in parent 0x0 (which has 1 children).
1
0
854
Feb ’22
NSStackView edgeInsets top vs bottom bug?
Hard to believe something this old doesn't work, but it appears so. I set the top to 10 and the bottom to 0, but it uses 10 for both. Am I doing something wrong, or is it a bug? sv.edgeInsets = .init(top: 10, left: 10, bottom: 0, right: 0) Screenshot: Full code example below. (This is the ViewController.swift file after creating a new Xcode project with "Interface" of "Storyboard". No other changes to the project template.) class ViewController: NSViewController {     override func viewDidLoad() {         super.viewDidLoad()         let sv = NSStackView()         sv.translatesAutoresizingMaskIntoConstraints = false         let v1 = ColoredBlock(.red, width: 20)         let v2 = ColoredBlock(.green, width: 20)         let v3 = ColoredBlock(.blue)         sv.addArrangedSubview(v1)         sv.addArrangedSubview(v2)         sv.addArrangedSubview(v3)         sv.spacing = 0         sv.edgeInsets = .init(top: 10, left: 10, bottom: 0, right: 0)         // sv.setContentHuggingPriority(.required, for: .vertical)         view.addSubview(sv)         pinToFourEdges(view, sv)     } } class ColoredBlock: NSView {     let intrinsicHeight: CGFloat     let intrinsicWidth: CGFloat     init(_ color: NSColor, width: CGFloat = NSView.noIntrinsicMetric, height: CGFloat = NSView.noIntrinsicMetric) {         intrinsicWidth = width         intrinsicHeight = height         super.init(frame: .zero)         self.wantsLayer = true         if let layer = self.layer {             layer.backgroundColor = color.cgColor         }     }     required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }     override var intrinsicContentSize: NSSize {         return NSSize(width: intrinsicWidth, height: intrinsicHeight)     } } public func pinToFourEdges(_ view1: NSView, _ view2: NSView) {     view1.topAnchor.constraint(equalTo: view2.topAnchor).isActive = true     view1.bottomAnchor.constraint(equalTo: view2.bottomAnchor).isActive = true     view1.leftAnchor.constraint(equalTo: view2.leftAnchor).isActive = true     view1.rightAnchor.constraint(equalTo: view2.rightAnchor).isActive = true }
Topic: UI Frameworks SubTopic: AppKit Tags:
0
0
644
Feb ’22
HelloTriangle in Swift: error about depth attachment pixel format
Hi,I'm trying to port this to Swift. https://developer.apple.com/documentation/metal/hello_triangleTo get it to run I had to add the following line to the renderer class. Any idea why it's not needed in the Objective-C version? pipelineStateDescriptor.depthAttachmentPixelFormat = metalView.depthStencilPixelFormatWithout it I get an error: -[MTLDebugRenderCommandEncoder validateFramebufferWithRenderPipelineState:]:1232: failed assertion `For depth attachment, the render pipeline's pixelFormat (MTLPixelFormatInvalid) does not match the framebuffer's pixelFormat (MTLPixelFormatDepth32Float).'Rob
3
0
5.8k
Dec ’21
Side by side Picker wheels failing in iOS 15
You used to be able to put two wheel Pickers side-by-side in an HStack, if you used .frame(...) to set the width, along with .clipped(). Example code from previous question here: https://developer.apple.com/forums/thread/127028 HStack(spacing: 0) { Picker(selection: $choice1, label: Text("C1")) { ForEach(0..<10) { n in Text("\(n) a").tag(n) } } .pickerStyle(.wheel) .frame(minWidth: 0) .clipped() // repeat with second Picker } This is not working for me now in iOS 15. The views still appear side by side, but the touch area seems to overlap. When you try to adjust the first wheel, it spins the second one. I can move the first wheel, if I touch way over to the leading side of the screen. (I had to add the explicit Picker style. It seems like defaulting to .menu also started in iOS 15. ?)
4
0
3k
Dec ’21
iOS 13, iPad Pro now says hardware does not support read-write texture?
I have some code that used to run on my iPad Pro. Today I compiled it for iOS 13, with Xcode 11, and I get errors like this: validateComputeFunctionArguments:834: failed assertion `Compute Function(merge_layer): Shader uses texture(outTexture[1]) as read-write, but hardware does not support read-write texture of this pixel format.'The pixel format is showing as `MTLPixelFormatBGRA8Unorm`. That's what I expected.The debugger says the device has no support for writeable textures. (lldb) p device.readWriteTextureSupport (MTLReadWriteTextureTier) $R25 = tierNoneDid some devices lose support for texture writing in iOS 13?Rob
12
0
5.2k
Dec ’21
Are Button actions on the MainActor?
I think they are, but I got myself into a situation with this error: // Inside a SwiftUI View struct... let cancelled: @MainActor () -> Void var body: some View { ... Button(action: self.cancelled) { Text("Cancel") } // Error here The compiler reports: Converting function value of type '@MainActor () -> Void' to '() -> Void' loses global actor 'MainActor' I originally put that attribute on the cancelled property, because in the passed-in closure, I was doing something that gave me an error about how I had to be on the MainActor.
4
2
2.9k
Dec ’21
How to build a replacement for sandbox-exec?
Hi, I want something like sandbox-exec, so I can run things that I don't trust, and restrict their ability to read or write files to only certain locations. Like most software devs I have to download and run lots of code from the internet and the danger of this really annoys me. Unfortunately sandbox-exec is marked as deprecated and the APIs in sandbox.h say "No longer supported". I notice there is some new stuff in the Apple docs about "hypervisors" and "virtualization". https://developer.apple.com/documentation/hypervisor https://developer.apple.com/documentation/virtualization Would these APIs allow me to start and control a virtual copy of my macOS, to serve like a sandbox? Are there other solutions that people use? As an example, say that I need to download and run a copy of memcached. It's a typical open source project – you unpack a source tgz, then run configure; make and get a binary. Now I want to run that without worrying that some hacker injected a piece of evil code to copy my files and send them somewhere. So I want to say "run this binary, while disallowing file reads and writes, except for directories X,Y,Z, and disallowing network connections, except for listening on port 1234."
12
0
5.0k
Nov ’21
Flush Metal rendering when program is paused in LLDB?
I watched a WWDC talk on LLDB, and they showed a nice trick of calling CATransaction.flush() from the debugger, to push changes to a UIView to the screen, even when the program was paused. Is there is a similar thing we can do with Metal? I'm using MTKView, but I can change to a lower level if that's required. The MTKView is paused, so I'm using setNeedsDisplay. As usual, I implement the draw delegate method to encode and commit a command buffer. If I do this from LLDB: metalView.setNeedsDisplay() CATransaction.flush() I can see that causes my draw function to run, but nothing shows up on screen. Is there something else we can do to flush those metal commands to the GPU and see them on screen while stepping through the program with the debugger?
1
0
955
Nov ’21
SwiftUI Text inside Text interpolation bug?
Why the does this display "Hello1" and not "HelloWorld"? Then if I put a space between them it works as expected. (macOS 12.0.1) struct ContentView: View {     var body: some View {         let t1 = Text("Hello").foregroundColor(.red)         let t2 = Text("World").foregroundColor(.blue)         Text("\(t1)\(t2)")             .padding()             .frame(width: 200)     } }
1
0
829
Nov ’21
How does SwiftUI update if objectWillChange fires *before* change
I'm wondering how SwiftUI updates work in connection with ObservableObjects. If a SwiftUI View depends on an `ObservableObject`, the object's `objectWillChange` publisher fires, and SwiftUI learns about the change, before the change happens. At this point, SwiftUI can't re-render a View, right? Because the new properties aren't there yet. So what does SwiftUI do? Does it schedule the change for later? That doesn't make sense either - how can it know when the object will be ready to be used in a new rendering of the UI? ~ Rob
Replies
3
Boosts
0
Views
5.4k
Activity
Feb ’22
Combining chars do not render right in some fonts
Here's a simple demo. I run it on macOS 12.1, compiled with Xcode 13.2. struct ContentView: View {     var body: some View {         VStack {             Text("ee")             Text("eé") Text("e\u{E9}") // "e with acute"             Text("ee\u{301}") // "combining acute"         }.font(.custom("Avenir", fixedSize: 18))          .padding(20)     } } In the 4rd one, the "e" is rendered in the wrong size/font. Screenshot: Other fonts do not have the problem. For example, "Avenir Next" and "Helvetica". Is there a way (in code) to tell which fonts can handle combining chars? Is this a bug? I notice the same thing happens when I use Core Text to draw the strings at a low level. So it's not just SwiftUI. In TextEdit, if have Avenir font, type "option-e" + "e" I get a nice letter. Maybe TextEdit is doing what Xcode did in the second line, and using the "e with acute" unicode character.
Replies
2
Boosts
0
Views
790
Activity
Feb ’22
Hierarchical List / OutlineGroup - can't change data?
Does anyone use the new hierarchical data List (ie, OutlineGroup) with a model where the tree data changes? I'm on Big Sur beta. I have code like this: List([treeRoot], children: \.children) { item in ... Say the treeRoot (observed object) gets a new child. The view tries to re-render and fails: 2020-09-21 ... [General] NSOutlineView error inserting child indexes <_NSCachedIndexSet: 0x600000760000>[number of indexes: 1 (in 1 ranges), indexes: (3)] in parent 0x0 (which has 1 children).
Replies
1
Boosts
0
Views
854
Activity
Feb ’22
NSStackView edgeInsets top vs bottom bug?
Hard to believe something this old doesn't work, but it appears so. I set the top to 10 and the bottom to 0, but it uses 10 for both. Am I doing something wrong, or is it a bug? sv.edgeInsets = .init(top: 10, left: 10, bottom: 0, right: 0) Screenshot: Full code example below. (This is the ViewController.swift file after creating a new Xcode project with "Interface" of "Storyboard". No other changes to the project template.) class ViewController: NSViewController {     override func viewDidLoad() {         super.viewDidLoad()         let sv = NSStackView()         sv.translatesAutoresizingMaskIntoConstraints = false         let v1 = ColoredBlock(.red, width: 20)         let v2 = ColoredBlock(.green, width: 20)         let v3 = ColoredBlock(.blue)         sv.addArrangedSubview(v1)         sv.addArrangedSubview(v2)         sv.addArrangedSubview(v3)         sv.spacing = 0         sv.edgeInsets = .init(top: 10, left: 10, bottom: 0, right: 0)         // sv.setContentHuggingPriority(.required, for: .vertical)         view.addSubview(sv)         pinToFourEdges(view, sv)     } } class ColoredBlock: NSView {     let intrinsicHeight: CGFloat     let intrinsicWidth: CGFloat     init(_ color: NSColor, width: CGFloat = NSView.noIntrinsicMetric, height: CGFloat = NSView.noIntrinsicMetric) {         intrinsicWidth = width         intrinsicHeight = height         super.init(frame: .zero)         self.wantsLayer = true         if let layer = self.layer {             layer.backgroundColor = color.cgColor         }     }     required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }     override var intrinsicContentSize: NSSize {         return NSSize(width: intrinsicWidth, height: intrinsicHeight)     } } public func pinToFourEdges(_ view1: NSView, _ view2: NSView) {     view1.topAnchor.constraint(equalTo: view2.topAnchor).isActive = true     view1.bottomAnchor.constraint(equalTo: view2.bottomAnchor).isActive = true     view1.leftAnchor.constraint(equalTo: view2.leftAnchor).isActive = true     view1.rightAnchor.constraint(equalTo: view2.rightAnchor).isActive = true }
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
0
Boosts
0
Views
644
Activity
Feb ’22
HelloTriangle in Swift: error about depth attachment pixel format
Hi,I'm trying to port this to Swift. https://developer.apple.com/documentation/metal/hello_triangleTo get it to run I had to add the following line to the renderer class. Any idea why it's not needed in the Objective-C version? pipelineStateDescriptor.depthAttachmentPixelFormat = metalView.depthStencilPixelFormatWithout it I get an error: -[MTLDebugRenderCommandEncoder validateFramebufferWithRenderPipelineState:]:1232: failed assertion `For depth attachment, the render pipeline's pixelFormat (MTLPixelFormatInvalid) does not match the framebuffer's pixelFormat (MTLPixelFormatDepth32Float).'Rob
Replies
3
Boosts
0
Views
5.8k
Activity
Dec ’21
Side by side Picker wheels failing in iOS 15
You used to be able to put two wheel Pickers side-by-side in an HStack, if you used .frame(...) to set the width, along with .clipped(). Example code from previous question here: https://developer.apple.com/forums/thread/127028 HStack(spacing: 0) { Picker(selection: $choice1, label: Text("C1")) { ForEach(0..<10) { n in Text("\(n) a").tag(n) } } .pickerStyle(.wheel) .frame(minWidth: 0) .clipped() // repeat with second Picker } This is not working for me now in iOS 15. The views still appear side by side, but the touch area seems to overlap. When you try to adjust the first wheel, it spins the second one. I can move the first wheel, if I touch way over to the leading side of the screen. (I had to add the explicit Picker style. It seems like defaulting to .menu also started in iOS 15. ?)
Replies
4
Boosts
0
Views
3k
Activity
Dec ’21
How to find forum post with old link?
I have developer documentation that contains links that are now dead. How can I find the post that this link used to refer to? https://forums.developer.apple.com/message/281700 I tried simply using the ID in the new URL format, but that didn't work. Eg: https://developer.apple.com/forums/thread/281700
Replies
2
Boosts
0
Views
830
Activity
Dec ’21
iOS 13, iPad Pro now says hardware does not support read-write texture?
I have some code that used to run on my iPad Pro. Today I compiled it for iOS 13, with Xcode 11, and I get errors like this: validateComputeFunctionArguments:834: failed assertion `Compute Function(merge_layer): Shader uses texture(outTexture[1]) as read-write, but hardware does not support read-write texture of this pixel format.'The pixel format is showing as `MTLPixelFormatBGRA8Unorm`. That's what I expected.The debugger says the device has no support for writeable textures. (lldb) p device.readWriteTextureSupport (MTLReadWriteTextureTier) $R25 = tierNoneDid some devices lose support for texture writing in iOS 13?Rob
Replies
12
Boosts
0
Views
5.2k
Activity
Dec ’21
Are Button actions on the MainActor?
I think they are, but I got myself into a situation with this error: // Inside a SwiftUI View struct... let cancelled: @MainActor () -> Void var body: some View { ... Button(action: self.cancelled) { Text("Cancel") } // Error here The compiler reports: Converting function value of type '@MainActor () -> Void' to '() -> Void' loses global actor 'MainActor' I originally put that attribute on the cancelled property, because in the passed-in closure, I was doing something that gave me an error about how I had to be on the MainActor.
Replies
4
Boosts
2
Views
2.9k
Activity
Dec ’21
How to build a replacement for sandbox-exec?
Hi, I want something like sandbox-exec, so I can run things that I don't trust, and restrict their ability to read or write files to only certain locations. Like most software devs I have to download and run lots of code from the internet and the danger of this really annoys me. Unfortunately sandbox-exec is marked as deprecated and the APIs in sandbox.h say "No longer supported". I notice there is some new stuff in the Apple docs about "hypervisors" and "virtualization". https://developer.apple.com/documentation/hypervisor https://developer.apple.com/documentation/virtualization Would these APIs allow me to start and control a virtual copy of my macOS, to serve like a sandbox? Are there other solutions that people use? As an example, say that I need to download and run a copy of memcached. It's a typical open source project – you unpack a source tgz, then run configure; make and get a binary. Now I want to run that without worrying that some hacker injected a piece of evil code to copy my files and send them somewhere. So I want to say "run this binary, while disallowing file reads and writes, except for directories X,Y,Z, and disallowing network connections, except for listening on port 1234."
Replies
12
Boosts
0
Views
5.0k
Activity
Nov ’21
Flush Metal rendering when program is paused in LLDB?
I watched a WWDC talk on LLDB, and they showed a nice trick of calling CATransaction.flush() from the debugger, to push changes to a UIView to the screen, even when the program was paused. Is there is a similar thing we can do with Metal? I'm using MTKView, but I can change to a lower level if that's required. The MTKView is paused, so I'm using setNeedsDisplay. As usual, I implement the draw delegate method to encode and commit a command buffer. If I do this from LLDB: metalView.setNeedsDisplay() CATransaction.flush() I can see that causes my draw function to run, but nothing shows up on screen. Is there something else we can do to flush those metal commands to the GPU and see them on screen while stepping through the program with the debugger?
Replies
1
Boosts
0
Views
955
Activity
Nov ’21
Reason a review shows in Connect app but not App Store?
I'm using the Connect app on my iPad. I'm looking at an app that is barely used, and I see two written reviews. But in the App Store there is only one. Any ideas what could cause this? The review in question is reporting a possible bug, so I do wonder if this means the user retracted/deleted it.
Replies
0
Boosts
0
Views
433
Activity
Nov ’21
Documentation comment "less than" character triggers monospace font?
Is this a bug? Is the < character supposed to change something in markdown? I didn't think so. (Xcode 13.1)
Replies
1
Boosts
0
Views
586
Activity
Nov ’21
SwiftUI Text inside Text interpolation bug?
Why the does this display "Hello1" and not "HelloWorld"? Then if I put a space between them it works as expected. (macOS 12.0.1) struct ContentView: View {     var body: some View {         let t1 = Text("Hello").foregroundColor(.red)         let t2 = Text("World").foregroundColor(.blue)         Text("\(t1)\(t2)")             .padding()             .frame(width: 200)     } }
Replies
1
Boosts
0
Views
829
Activity
Nov ’21
Disable device rotation animation in SwiftUI?
I'm working on a drawing and painting program. When I turn my iPad, I detect the screen change and keep the drawing stable, while allowing the toolbars and things to rotate. But SwiftUI creates a disorienting animation of the main canvas anyway. Is there a way to shut that off?
Replies
0
Boosts
4
Views
949
Activity
Oct ’21