Post

Replies

Boosts

Views

Activity

GlobalActor directive doesn't guarantee a function will be called on that actor?
Assuming I have defined a global actor: @globalActor actor MyActor { static let shared = MyActor() } And I have a class, in which a couple of methods need to act under this: class MyClass { @MyActor func doSomething(undoManager: UndoManager) { // Do something here undoManager?.registerUndo(withTarget: self) { $0.reverseSomething(undoManager: UndoManager) } } @MyActor func reverseSomething(undoManager: UndoManager) { // Do the reverse of something here print(\(Thread.isMainThread) /// Prints true when called from undo stack undoManager?.registerUndo(withTarget: self) { $0.doSomething(undoManager: UndoManager) } } } Assume the code gets called from a SwiftUI view: struct MyView: View { @Environment(\.undoManager) private var undoManager: UndoManager? let myObject: MyClass var body: some View { Button("Do something") { myObject.doSomething(undoManager: undoManager) } } } Note that when the action is undone the 'reversing' func it is called on the MainThread. Is the correct way to prevent this to wrap the undo action in a task? As in: @MyActor func reverseSomething(undoManager: UndoManager) { // Do the reverse of something here print(\(Thread.isMainThread) /// Prints true undoManager?.registerUndo(withTarget: self) { Task { $0.doSomething(undoManager: UndoManager) } } }
0
0
1k
Jul ’22
Security scoped bookmark and external drives
I'm writing a photo management app where the document stores the location of folders (in which image files reside). These are added by the user, and saved as security scoped bookmarks. All this appeared to be working. However, I tested a use-case where the user starts working on one machine where they add a folder, which resides on an external drive. This works, as long as they remain the on the same machine. However, if they move to another machine, plug in the external drive and then load up the document it fails to resolve the bookmark, throws the following error: Error Domain=NSCocoaErrorDomain Code=259 "The file couldn’t be opened because it isn’t in the correct format." For completeness here is the code to resolve the bookmark: do { let url = try URL( resolvingBookmarkData: data, options: Self.bookmarkResolutionOptions, relativeTo: nil, bookmarkDataIsStale: &isStale ) } catch { print(error) /// ... error handling code here } Do I therefore assume that I cannot achieve this, and will have to ask the user to re-authorise this folder on the second machine?
1
0
1.3k
Nov ’22
Passing locale into a RegexBuilder as a parameter
I am building a tokeniser, and would like to hold this as a struct, passing in a locale during initiation. Here's the gist of what I would want to write: struct Tokeniser { private let locale: Locale private let integerRegex: Regex init(locale: Locale) { self.locale: Locale self.integerRegex = Regex { Capture { .localizedInteger(locale: locale) } transform: { Token.number($0) } } } func parse(text: String) -> Token { if let match = try integerRegex.firstMatch(in: text) { //... other code here } } \\...other code here } As Regex is generic the compiler suggests to set the integerRegex's type to Regex<Any>, but this triggers another set of compiler issues that I have not been able to figure out what the type should be. So then I tried to write something like this (inspired by SwiftUI): var integerRegex: some Regex { Capture { .localizedInteger(locale: locale) } transform: { Token.number($0) } } But again, the compiler prompts me to enter Regex. The only way I have to be able to get the struct to compiler is to create lazy variables, which then have the side effect that I have to mark my functions as mutable, which have downstream issues when they are called from with SwiftUI structs. lazy var integerRegex = Regex { Capture { .localizedInteger(locale: locale) } } mutating func parse(text: String) -> Token { if let match = try integerRegex.firstMatch(in: text) { } } How can I code this?
0
0
527
Oct ’23
Updating metadata properties of a DNG (or other) format image
Hi, I'm looking to update the metadata properties of a DNG image stored on disc, saving to a new file. Using ImageIO's CGImageSource and CGImageDestination classes, I run into a problem where by the destination doesn't support the type of the source. For example: let imageSourceOptions = [kCGImageSourceShouldCache: false] as CFDictionary if let cgImageSource = CGImageSourceCreateWithURL(sourceURL as CFURL, imageSourceOptions), let type = CGImageSourceGetType(cgImageSource) { guard let imageDestination = CGImageDestinationCreateWithURL(destinationURL as CFURL, type, 1, nil) else { fatalError("Unable to create image destination") } // Code to update properties and write out to destination url } } When this code is executed I get the following errors on the command line when trying to create the destination: 2024-06-30 11:52:25.531530+0100 ABC[7564:273101] [ABC] findWriterForTypeAndAlternateType:119: *** ERROR: unsupported output file format 'com.adobe.raw-image' 2024-06-30 11:52:25.531661+0100 ABC[7564:273101] [ABC] CGImageDestinationCreateWithURL:4429: *** ERROR: CGImageDestinationCreateWithURL: failed to create 'CGImageDestinationRef' I don't see a way to create a destination directly from a source? Yes, the code works for say a JPEG file but I want it to work for any image format that CGImageSource can work with?
0
0
757
Jun ’24
Creating and applying a shader to change an entity's rendering in RealityKit
Hello, I am looking to create a shader to update an entity's rendering. As a basic example say I want to recolour an entity, but leave its original textures showing through: I understand with VisionOS I need to use Reality Composer Pro to create the shader, but I'm lost as how to reference the original colour that I'm trying to update in the node graph. All my attempts appear to completely override the textures in the entity (and its sub-entities) that I want to impact. Also the tutorials / examples I've looked at appear to create materials, not add an effect on top of existing materials. Any hints or pointers? Assuming this is possible, I've been trying to load the material in code, and apply to an entity. But do I need to do this to all child entities, or just the topmost? do { let entity = MyAssets.createModelEntity(.plane) // Loads from bundle and performs config let material = try await ShaderGraphMaterial(named: "/Root/TestMaterial", from: "Test", in: realityKitContentBundle) entity.applyToChildren { $0.components[ModelComponent.self]?.materials = [material] } root.addChild(entity) } catch { fatalError(error.localizedDescription) }
3
0
958
Oct ’24
Custom EntityAction - different behaviour VisionOS 2.6 vs 26
I implemented an EntityAction to change the baseColor tint - and had it working on VisionOS 2.x. import RealityKit import UIKit typealias Float4 = SIMD4<Float> extension UIColor { var float4: Float4 { if cgColor.numberOfComponents == 4, let c = cgColor.components { Float4(Float(c[0]), Float(c[1]), Float(c[2]), Float(c[3])) } else { Float4() } } } struct ColourAction: EntityAction { // MARK: - PUBLIC PROPERTIES let startColour: Float4 let targetColour: Float4 // MARK: - PUBLIC COMPUTED PROPERTIES var animatedValueType: (any AnimatableData.Type)? { Float4.self } // MARK: - INITIATION init(startColour: UIColor, targetColour: UIColor) { self.startColour = startColour.float4 self.targetColour = targetColour.float4 } // MARK: - PUBLIC STATIC FUNCTIONS @MainActor static func registerEntityAction() { ColourAction.subscribe(to: .updated) { event in guard let animationState = event.animationState else { return } let interpolatedColour = event.action.startColour.mixedWith(event.action.targetColour, by: Float(animationState.normalizedTime)) animationState.storeAnimatedValue(interpolatedColour) } } } extension Entity { // MARK: - PUBLIC FUNCTIONS func changeColourTo(_ targetColour: UIColor, duration: Double) { guard let modelComponent = components[ModelComponent.self], let material = modelComponent.materials.first as? PhysicallyBasedMaterial else { return } let colourAction = ColourAction(startColour: material.baseColor.tint, targetColour: targetColour) if let colourAnimation = try? AnimationResource.makeActionAnimation(for: colourAction, duration: duration, bindTarget: .material(0).baseColorTint) { playAnimation(colourAnimation) } } } This doesn't work in VisionOS 26. My current fix is to directly set the material base colour - but this feels like the wrong approach: @MainActor static func registerEntityAction() { ColourAction.subscribe(to: .updated) { event in guard let animationState = event.animationState, let entity = event.targetEntity, let modelComponent = entity.components[ModelComponent.self], var material = modelComponent.materials.first as? PhysicallyBasedMaterial else { return } let interpolatedColour = event.action.startColour.mixedWith(event.action.targetColour, by: Float(animationState.normalizedTime)) material.baseColor.tint = UIColor(interpolatedColour) entity.components[ModelComponent.self]?.materials[0] = material animationState.storeAnimatedValue(interpolatedColour) } } So before I raise this as a bug, was I doing anything wrong in the former version and got lucky? Is there a better approach?
0
0
153
Sep ’25
SwiftUI Picker layout under MacOS26
Prior to MacOS 26, Multiple Pickers could be laid out with a uniform width. For example: struct LayoutExample: View { let fruits = ["apple", "banana", "orange", "kiwi"] let veg = ["carrot", "cauliflower", "peas", "Floccinaucinihilipilification Cucurbitaceae"] @State private var selectedFruit: String = "kiwi" @State private var selectedVeg: String = "carrot" var body: some View { VStack(alignment: .leading) { Picker(selection: $selectedFruit) { ForEach(fruits, id: \.self, content: Text.init) } label: { Text("Fruity choice") .frame(width: 150, alignment: .trailing) } .frame(width: 300) Picker(selection: $selectedVeg) { ForEach(veg, id: \.self, content: Text.init) } label: { Text("Veg") .frame(width: 150, alignment: .trailing) } .frame(width: 300) } } } Renders like this, prior to MacOS26: But now looks like this under MacOS 26: Is there anyway to control the size of the picker selection in MacOS 26?
1
0
123
Sep ’25
VideoPlayer crashes on Archive build
I have found that following code runs without issue from Xcode, either in Debug or Release mode, yet crashes when running from the binary produced by archiving - i.e. what will be sent to the app store. import SwiftUI import AVKit @main struct tcApp: App { var body: some Scene { WindowGroup { VideoPlayer(player: nil) } } } This is the most stripped down code that shows the issue. One can try and point the VideoPlayer at a file and the same issue will occur. I've attached the crash log: Crash log Please note that this was seen with Xcode 26.2 and MacOS 26.2.
1
0
541
Dec ’25
How to correctly move a TextField selection cursor when inserting UTF16 text
I'm trying to implement a feature whereby a user can tap a button to insert a character at the cursor in a TextField - the cursor then needs to be moved forward to be in front of the insert character. I'm having trouble with characters such as π which are UTF16 encoded. In the following sample app, enter the following sequence: Enter 9 by keyboard tap + Enter 9 by keyboard tap π Enter 9 via keyboard tap + he TextField will show '9+9π+9' (i.e. the final + is inserted before 9 rather than after it. Any insight into what I am doing wrong? import SwiftUI @main struct TextInsertApp: App { var body: some Scene { WindowGroup { ContentView() } } } struct ContentView: View { @State private var text: String = "" @State private var selection: TextSelection? = nil var body: some View { TextField("", text: $text, selection: $selection) .background(.gray.opacity(0.4)) Button("+") { insert("+") } Button("π") { insert("π") } } func insert(_ insertString: String) { if let selection { if case let .selection(range) = selection.indices { if selection.isInsertion { text.insert(contentsOf: insertString, at: range.lowerBound) } else { text.replaceSubrange(range, with: insertString) } let cursor = text.utf16.index(range.upperBound, offsetBy: insertString.count) self.selection = .init(insertionPoint: cursor) } } else { text += insertString selection = .init(range: text.utf16.endIndex..<text.utf16.endIndex) } } }
1
0
182
Jan ’26
Orphaned XCode simulator disk images
Recently I noticed that although my drive showed ~800Gb of usage, the folders within totally to around ~600Gb (and yes I was including hidden 'dot' files/folders. After some inspection I found that there are a whole set of Disk Media Images, that appear to be related to XCode simulators. Here's an extract from the command line diskutil list command: /dev/disk5 (synthesized): #: TYPE NAME SIZE IDENTIFIER 0: APFS Container Scheme - +17.6 GB disk5 Physical Store disk4s1 1: APFS Volume iOS 26.2 Simulator 17.1 GB disk5s1 /dev/disk6 (disk image): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme +14.2 GB disk6 1: Apple_APFS Container disk7 14.2 GB disk6s1 /dev/disk7 (synthesized): #: TYPE NAME SIZE IDENTIFIER 0: APFS Container Scheme - +14.2 GB disk7 Physical Store disk6s1 1: APFS Volume XROS 26.2 Simulator 13.8 GB disk7s1 /dev/disk8 (disk image): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme +17.2 GB disk8 1: Apple_APFS Container disk9 17.2 GB disk8s1 /dev/disk9 (synthesized): #: TYPE NAME SIZE IDENTIFIER 0: APFS Container Scheme - +17.2 GB disk9 Physical Store disk8s1 1: APFS Volume iOS 26.0 Simulator 16.7 GB disk9s1 /dev/disk10 (disk image): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme +8.5 GB disk10 1: Apple_APFS Container disk11 8.5 GB disk10s1 /dev/disk11 (synthesized): #: TYPE NAME SIZE IDENTIFIER 0: APFS Container Scheme - +8.5 GB disk11 Physical Store disk10s1 1: APFS Volume XROS 2.5 Simulator B... 8.2 GB disk11s1 /dev/disk12 (disk image): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme +18.0 GB disk12 1: Apple_APFS Container disk13 18.0 GB disk12s1 /dev/disk13 (synthesized): #: TYPE NAME SIZE IDENTIFIER 0: APFS Container Scheme - +18.0 GB disk13 Physical Store disk12s1 1: APFS Volume XROS 2.5 Simulator 17.5 GB disk13s1 /dev/disk14 (disk image): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme +17.6 GB disk14 1: Apple_APFS Container disk15 17.6 GB disk14s1 /dev/disk15 (synthesized): #: TYPE NAME SIZE IDENTIFIER 0: APFS Container Scheme - +17.6 GB disk15 Physical Store disk14s1 1: APFS Volume iOS 26.1 Simulator 17.1 GB disk15s1 /dev/disk16 (disk image): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme +14.1 GB disk16 1: Apple_APFS Container disk17 14.1 GB disk16s1 /dev/disk17 (synthesized): #: TYPE NAME SIZE IDENTIFIER 0: APFS Container Scheme - +14.1 GB disk17 Physical Store disk16s1 1: APFS Volume XROS 26.1 Simulator 13.7 GB disk17s1 /dev/disk18 (disk image): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme +17.6 GB disk18 1: Apple_APFS Container disk19 17.6 GB disk18s1 /dev/disk19 (synthesized): #: TYPE NAME SIZE IDENTIFIER 0: APFS Container Scheme - +17.6 GB disk19 Physical Store disk18s1 1: APFS Volume iOS 26.1 Simulator 17.1 GB disk19s1 /dev/disk20 (disk image): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme +9.1 GB disk20 1: Apple_APFS Container disk21 9.1 GB disk20s1 /dev/disk21 (synthesized): #: TYPE NAME SIZE IDENTIFIER 0: APFS Container Scheme - +9.1 GB disk21 Physical Store disk20s1 1: APFS Volume iOS 18.5 Simulator B... 8.8 GB disk21s1 /dev/disk22 (disk image): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme +20.7 GB disk22 1: Apple_APFS Container disk23 20.7 GB disk22s1 /dev/disk23 (synthesized): #: TYPE NAME SIZE IDENTIFIER 0: APFS Container Scheme - +20.7 GB disk23 Physical Store disk22s1 1: APFS Volume iOS 18.5 Simulator 20.2 GB disk23s1 I am unable to unmount them, either from the command line or Disk Utility. How do I go about this?
1
0
71
1w
GlobalActor directive doesn't guarantee a function will be called on that actor?
Assuming I have defined a global actor: @globalActor actor MyActor { static let shared = MyActor() } And I have a class, in which a couple of methods need to act under this: class MyClass { @MyActor func doSomething(undoManager: UndoManager) { // Do something here undoManager?.registerUndo(withTarget: self) { $0.reverseSomething(undoManager: UndoManager) } } @MyActor func reverseSomething(undoManager: UndoManager) { // Do the reverse of something here print(\(Thread.isMainThread) /// Prints true when called from undo stack undoManager?.registerUndo(withTarget: self) { $0.doSomething(undoManager: UndoManager) } } } Assume the code gets called from a SwiftUI view: struct MyView: View { @Environment(\.undoManager) private var undoManager: UndoManager? let myObject: MyClass var body: some View { Button("Do something") { myObject.doSomething(undoManager: undoManager) } } } Note that when the action is undone the 'reversing' func it is called on the MainThread. Is the correct way to prevent this to wrap the undo action in a task? As in: @MyActor func reverseSomething(undoManager: UndoManager) { // Do the reverse of something here print(\(Thread.isMainThread) /// Prints true undoManager?.registerUndo(withTarget: self) { Task { $0.doSomething(undoManager: UndoManager) } } }
Replies
0
Boosts
0
Views
1k
Activity
Jul ’22
Security scoped bookmark and external drives
I'm writing a photo management app where the document stores the location of folders (in which image files reside). These are added by the user, and saved as security scoped bookmarks. All this appeared to be working. However, I tested a use-case where the user starts working on one machine where they add a folder, which resides on an external drive. This works, as long as they remain the on the same machine. However, if they move to another machine, plug in the external drive and then load up the document it fails to resolve the bookmark, throws the following error: Error Domain=NSCocoaErrorDomain Code=259 "The file couldn’t be opened because it isn’t in the correct format." For completeness here is the code to resolve the bookmark: do { let url = try URL( resolvingBookmarkData: data, options: Self.bookmarkResolutionOptions, relativeTo: nil, bookmarkDataIsStale: &amp;isStale ) } catch { print(error) /// ... error handling code here } Do I therefore assume that I cannot achieve this, and will have to ask the user to re-authorise this folder on the second machine?
Replies
1
Boosts
0
Views
1.3k
Activity
Nov ’22
Passing locale into a RegexBuilder as a parameter
I am building a tokeniser, and would like to hold this as a struct, passing in a locale during initiation. Here's the gist of what I would want to write: struct Tokeniser { private let locale: Locale private let integerRegex: Regex init(locale: Locale) { self.locale: Locale self.integerRegex = Regex { Capture { .localizedInteger(locale: locale) } transform: { Token.number($0) } } } func parse(text: String) -> Token { if let match = try integerRegex.firstMatch(in: text) { //... other code here } } \\...other code here } As Regex is generic the compiler suggests to set the integerRegex's type to Regex<Any>, but this triggers another set of compiler issues that I have not been able to figure out what the type should be. So then I tried to write something like this (inspired by SwiftUI): var integerRegex: some Regex { Capture { .localizedInteger(locale: locale) } transform: { Token.number($0) } } But again, the compiler prompts me to enter Regex. The only way I have to be able to get the struct to compiler is to create lazy variables, which then have the side effect that I have to mark my functions as mutable, which have downstream issues when they are called from with SwiftUI structs. lazy var integerRegex = Regex { Capture { .localizedInteger(locale: locale) } } mutating func parse(text: String) -> Token { if let match = try integerRegex.firstMatch(in: text) { } } How can I code this?
Replies
0
Boosts
0
Views
527
Activity
Oct ’23
Xcode not picking up changes to Unit Test files
Xcode is not not picking up when I make changes to my unit test files when running tests. The only way is to clean the whole project and rebuild again. Any ideas why? I recently tried Xcode cloud and this behaviour started after removing that option
Replies
0
Boosts
0
Views
708
Activity
Feb ’24
Using TriggerVolume to detect collisions
Does anyone have any guidance / experience using TriggerVolumes to detect collision rather than the Physics engine in Reality Kit. Aside from not participating the physics engine are there any other downside or upsides to using them?
Replies
0
Boosts
0
Views
700
Activity
May ’24
Updating metadata properties of a DNG (or other) format image
Hi, I'm looking to update the metadata properties of a DNG image stored on disc, saving to a new file. Using ImageIO's CGImageSource and CGImageDestination classes, I run into a problem where by the destination doesn't support the type of the source. For example: let imageSourceOptions = [kCGImageSourceShouldCache: false] as CFDictionary if let cgImageSource = CGImageSourceCreateWithURL(sourceURL as CFURL, imageSourceOptions), let type = CGImageSourceGetType(cgImageSource) { guard let imageDestination = CGImageDestinationCreateWithURL(destinationURL as CFURL, type, 1, nil) else { fatalError("Unable to create image destination") } // Code to update properties and write out to destination url } } When this code is executed I get the following errors on the command line when trying to create the destination: 2024-06-30 11:52:25.531530+0100 ABC[7564:273101] [ABC] findWriterForTypeAndAlternateType:119: *** ERROR: unsupported output file format 'com.adobe.raw-image' 2024-06-30 11:52:25.531661+0100 ABC[7564:273101] [ABC] CGImageDestinationCreateWithURL:4429: *** ERROR: CGImageDestinationCreateWithURL: failed to create 'CGImageDestinationRef' I don't see a way to create a destination directly from a source? Yes, the code works for say a JPEG file but I want it to work for any image format that CGImageSource can work with?
Replies
0
Boosts
0
Views
757
Activity
Jun ’24
Creating and applying a shader to change an entity's rendering in RealityKit
Hello, I am looking to create a shader to update an entity's rendering. As a basic example say I want to recolour an entity, but leave its original textures showing through: I understand with VisionOS I need to use Reality Composer Pro to create the shader, but I'm lost as how to reference the original colour that I'm trying to update in the node graph. All my attempts appear to completely override the textures in the entity (and its sub-entities) that I want to impact. Also the tutorials / examples I've looked at appear to create materials, not add an effect on top of existing materials. Any hints or pointers? Assuming this is possible, I've been trying to load the material in code, and apply to an entity. But do I need to do this to all child entities, or just the topmost? do { let entity = MyAssets.createModelEntity(.plane) // Loads from bundle and performs config let material = try await ShaderGraphMaterial(named: "/Root/TestMaterial", from: "Test", in: realityKitContentBundle) entity.applyToChildren { $0.components[ModelComponent.self]?.materials = [material] } root.addChild(entity) } catch { fatalError(error.localizedDescription) }
Replies
3
Boosts
0
Views
958
Activity
Oct ’24
How to track down issues in debug memory graph
When I run the debug memory graph from Xcode I'm getting a set of system objects with warnings. Are there any tips on how to locate what might be causing these?
Replies
0
Boosts
0
Views
109
Activity
Jun ’25
Custom EntityAction - different behaviour VisionOS 2.6 vs 26
I implemented an EntityAction to change the baseColor tint - and had it working on VisionOS 2.x. import RealityKit import UIKit typealias Float4 = SIMD4<Float> extension UIColor { var float4: Float4 { if cgColor.numberOfComponents == 4, let c = cgColor.components { Float4(Float(c[0]), Float(c[1]), Float(c[2]), Float(c[3])) } else { Float4() } } } struct ColourAction: EntityAction { // MARK: - PUBLIC PROPERTIES let startColour: Float4 let targetColour: Float4 // MARK: - PUBLIC COMPUTED PROPERTIES var animatedValueType: (any AnimatableData.Type)? { Float4.self } // MARK: - INITIATION init(startColour: UIColor, targetColour: UIColor) { self.startColour = startColour.float4 self.targetColour = targetColour.float4 } // MARK: - PUBLIC STATIC FUNCTIONS @MainActor static func registerEntityAction() { ColourAction.subscribe(to: .updated) { event in guard let animationState = event.animationState else { return } let interpolatedColour = event.action.startColour.mixedWith(event.action.targetColour, by: Float(animationState.normalizedTime)) animationState.storeAnimatedValue(interpolatedColour) } } } extension Entity { // MARK: - PUBLIC FUNCTIONS func changeColourTo(_ targetColour: UIColor, duration: Double) { guard let modelComponent = components[ModelComponent.self], let material = modelComponent.materials.first as? PhysicallyBasedMaterial else { return } let colourAction = ColourAction(startColour: material.baseColor.tint, targetColour: targetColour) if let colourAnimation = try? AnimationResource.makeActionAnimation(for: colourAction, duration: duration, bindTarget: .material(0).baseColorTint) { playAnimation(colourAnimation) } } } This doesn't work in VisionOS 26. My current fix is to directly set the material base colour - but this feels like the wrong approach: @MainActor static func registerEntityAction() { ColourAction.subscribe(to: .updated) { event in guard let animationState = event.animationState, let entity = event.targetEntity, let modelComponent = entity.components[ModelComponent.self], var material = modelComponent.materials.first as? PhysicallyBasedMaterial else { return } let interpolatedColour = event.action.startColour.mixedWith(event.action.targetColour, by: Float(animationState.normalizedTime)) material.baseColor.tint = UIColor(interpolatedColour) entity.components[ModelComponent.self]?.materials[0] = material animationState.storeAnimatedValue(interpolatedColour) } } So before I raise this as a bug, was I doing anything wrong in the former version and got lucky? Is there a better approach?
Replies
0
Boosts
0
Views
153
Activity
Sep ’25
SwiftUI Picker layout under MacOS26
Prior to MacOS 26, Multiple Pickers could be laid out with a uniform width. For example: struct LayoutExample: View { let fruits = ["apple", "banana", "orange", "kiwi"] let veg = ["carrot", "cauliflower", "peas", "Floccinaucinihilipilification Cucurbitaceae"] @State private var selectedFruit: String = "kiwi" @State private var selectedVeg: String = "carrot" var body: some View { VStack(alignment: .leading) { Picker(selection: $selectedFruit) { ForEach(fruits, id: \.self, content: Text.init) } label: { Text("Fruity choice") .frame(width: 150, alignment: .trailing) } .frame(width: 300) Picker(selection: $selectedVeg) { ForEach(veg, id: \.self, content: Text.init) } label: { Text("Veg") .frame(width: 150, alignment: .trailing) } .frame(width: 300) } } } Renders like this, prior to MacOS26: But now looks like this under MacOS 26: Is there anyway to control the size of the picker selection in MacOS 26?
Replies
1
Boosts
0
Views
123
Activity
Sep ’25
VideoPlayer crashes on Archive build
I have found that following code runs without issue from Xcode, either in Debug or Release mode, yet crashes when running from the binary produced by archiving - i.e. what will be sent to the app store. import SwiftUI import AVKit @main struct tcApp: App { var body: some Scene { WindowGroup { VideoPlayer(player: nil) } } } This is the most stripped down code that shows the issue. One can try and point the VideoPlayer at a file and the same issue will occur. I've attached the crash log: Crash log Please note that this was seen with Xcode 26.2 and MacOS 26.2.
Replies
1
Boosts
0
Views
541
Activity
Dec ’25
How to correctly move a TextField selection cursor when inserting UTF16 text
I'm trying to implement a feature whereby a user can tap a button to insert a character at the cursor in a TextField - the cursor then needs to be moved forward to be in front of the insert character. I'm having trouble with characters such as π which are UTF16 encoded. In the following sample app, enter the following sequence: Enter 9 by keyboard tap + Enter 9 by keyboard tap π Enter 9 via keyboard tap + he TextField will show '9+9π+9' (i.e. the final + is inserted before 9 rather than after it. Any insight into what I am doing wrong? import SwiftUI @main struct TextInsertApp: App { var body: some Scene { WindowGroup { ContentView() } } } struct ContentView: View { @State private var text: String = "" @State private var selection: TextSelection? = nil var body: some View { TextField("", text: $text, selection: $selection) .background(.gray.opacity(0.4)) Button("+") { insert("+") } Button("π") { insert("π") } } func insert(_ insertString: String) { if let selection { if case let .selection(range) = selection.indices { if selection.isInsertion { text.insert(contentsOf: insertString, at: range.lowerBound) } else { text.replaceSubrange(range, with: insertString) } let cursor = text.utf16.index(range.upperBound, offsetBy: insertString.count) self.selection = .init(insertionPoint: cursor) } } else { text += insertString selection = .init(range: text.utf16.endIndex..<text.utf16.endIndex) } } }
Replies
1
Boosts
0
Views
182
Activity
Jan ’26
Orphaned XCode simulator disk images
Recently I noticed that although my drive showed ~800Gb of usage, the folders within totally to around ~600Gb (and yes I was including hidden 'dot' files/folders. After some inspection I found that there are a whole set of Disk Media Images, that appear to be related to XCode simulators. Here's an extract from the command line diskutil list command: /dev/disk5 (synthesized): #: TYPE NAME SIZE IDENTIFIER 0: APFS Container Scheme - +17.6 GB disk5 Physical Store disk4s1 1: APFS Volume iOS 26.2 Simulator 17.1 GB disk5s1 /dev/disk6 (disk image): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme +14.2 GB disk6 1: Apple_APFS Container disk7 14.2 GB disk6s1 /dev/disk7 (synthesized): #: TYPE NAME SIZE IDENTIFIER 0: APFS Container Scheme - +14.2 GB disk7 Physical Store disk6s1 1: APFS Volume XROS 26.2 Simulator 13.8 GB disk7s1 /dev/disk8 (disk image): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme +17.2 GB disk8 1: Apple_APFS Container disk9 17.2 GB disk8s1 /dev/disk9 (synthesized): #: TYPE NAME SIZE IDENTIFIER 0: APFS Container Scheme - +17.2 GB disk9 Physical Store disk8s1 1: APFS Volume iOS 26.0 Simulator 16.7 GB disk9s1 /dev/disk10 (disk image): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme +8.5 GB disk10 1: Apple_APFS Container disk11 8.5 GB disk10s1 /dev/disk11 (synthesized): #: TYPE NAME SIZE IDENTIFIER 0: APFS Container Scheme - +8.5 GB disk11 Physical Store disk10s1 1: APFS Volume XROS 2.5 Simulator B... 8.2 GB disk11s1 /dev/disk12 (disk image): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme +18.0 GB disk12 1: Apple_APFS Container disk13 18.0 GB disk12s1 /dev/disk13 (synthesized): #: TYPE NAME SIZE IDENTIFIER 0: APFS Container Scheme - +18.0 GB disk13 Physical Store disk12s1 1: APFS Volume XROS 2.5 Simulator 17.5 GB disk13s1 /dev/disk14 (disk image): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme +17.6 GB disk14 1: Apple_APFS Container disk15 17.6 GB disk14s1 /dev/disk15 (synthesized): #: TYPE NAME SIZE IDENTIFIER 0: APFS Container Scheme - +17.6 GB disk15 Physical Store disk14s1 1: APFS Volume iOS 26.1 Simulator 17.1 GB disk15s1 /dev/disk16 (disk image): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme +14.1 GB disk16 1: Apple_APFS Container disk17 14.1 GB disk16s1 /dev/disk17 (synthesized): #: TYPE NAME SIZE IDENTIFIER 0: APFS Container Scheme - +14.1 GB disk17 Physical Store disk16s1 1: APFS Volume XROS 26.1 Simulator 13.7 GB disk17s1 /dev/disk18 (disk image): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme +17.6 GB disk18 1: Apple_APFS Container disk19 17.6 GB disk18s1 /dev/disk19 (synthesized): #: TYPE NAME SIZE IDENTIFIER 0: APFS Container Scheme - +17.6 GB disk19 Physical Store disk18s1 1: APFS Volume iOS 26.1 Simulator 17.1 GB disk19s1 /dev/disk20 (disk image): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme +9.1 GB disk20 1: Apple_APFS Container disk21 9.1 GB disk20s1 /dev/disk21 (synthesized): #: TYPE NAME SIZE IDENTIFIER 0: APFS Container Scheme - +9.1 GB disk21 Physical Store disk20s1 1: APFS Volume iOS 18.5 Simulator B... 8.8 GB disk21s1 /dev/disk22 (disk image): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme +20.7 GB disk22 1: Apple_APFS Container disk23 20.7 GB disk22s1 /dev/disk23 (synthesized): #: TYPE NAME SIZE IDENTIFIER 0: APFS Container Scheme - +20.7 GB disk23 Physical Store disk22s1 1: APFS Volume iOS 18.5 Simulator 20.2 GB disk23s1 I am unable to unmount them, either from the command line or Disk Utility. How do I go about this?
Replies
1
Boosts
0
Views
71
Activity
1w