Search results for

“swiftui”

17,235 results found

Post

Replies

Boosts

Views

Activity

Reply to SwiftUI onChange fires twice when filtering data from @Observable store
This is a very interesting question, and you've done a great job of isolating the behavior and providing comparative examples. I’m not an expert on SwiftUI, wish I knew better, but that technology was always being really good at what you're seeing this double update with @Observable and @State, especially in conjunction with GeometryReader. When @Published properties change, they emit events. Views that are observing these properties (via @StateObject or @EnvironmentObject) then get scheduled for re-evaluation. The update cycle is generally more straightforward: state change -> event -> view re-render. filteredAlbums id: [3878E7A7-CDAB-444F-8B8C-263763735770, 1, 2, 3, 4, 5, 6] filteredAlbums id: [1, 2, 3, 4, 5, 6] You've triggered two state changes almost simultaneously: albumStore.addAlbum(newAlbum): This is a change to a property managed by your @Observable AlbumStore. albumToAdd = newAlbum: This is a change to a @State property within your view. Your carousel() function reads from albumStore
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’26
Showing 3D/AR content on multiple pages in iOS with RealityView
Hi. I'm trying to show 3D or AR content in multiple pages on an iOS app but I have found that if a RealityView is used earlier in a flow then future uses will never display the camera feed, even if those earlier uses do not use any spatial tracking. For example, in the following simplified view, the second page realityView will not display the camera feed even though the first view does not use it not start a tracking session. struct ContentView: View { var body: some View { NavigationStack { VStack { RealityView { content in content.camera = .virtual // showing model skipped for brevity } NavigationLink(Second Page) { RealityView { content in content.camera = .spatialTracking } } } } } } What is the way around this so that 3D content can be displayed in multiple places in the app without preventing AR content from working? I have also found the same problem when wrapping an ARView for use in SwiftUI.
0
0
524
Feb ’26
How to Integrate Apple Wallet with Custom FinTech Apps
Hi everyone, With the rapid growth of digital banking, payments, and AI-driven financial services, building secure and scalable FinTech apps on iOS has become more complex than ever. From handling sensitive user data to ensuring compliance and seamless performance, iOS developers face multiple technical challenges. Key areas that usually require deep expertise include: Apple Pay and Wallet integrations Secure authentication (Face ID / Touch ID / biometrics) Real-time transaction processing Core ML for financial predictions SwiftUI dashboards for financial analytics Data encryption and regulatory compliance https://www.nimbleappgenie.com At Nimble AppGenie, we’ve worked extensively as a FinTech app development expert, helping startups and enterprises design and build iOS financial applications that are secure, scalable, and user-centric. Our experience shows that the most successful fintech apps are those that balance strong security architecture with intuitive UX and performance optimization. I’m int
0
0
599
Feb ’26
SwiftUI onChange fires twice when filtering data from @Observable store
Hi all, I’m running into a “double update” effect in SwiftUI when using the @Observable with @State. I’m trying to understand whether this is expected behavior, a misuse on my side, or a potential bug. Setup I have an observable store using the Observation macro: @Observable class AlbumStore { var albums: [Album] = [ Album(id: 1, title: Album 1, author: user1), Album(id: 2, title: Album 2, author: user1), Album(id: 3, title: Album 3, author: user1), Album(id: 4, title: Album 4, author: user1), Album(id: 5, title: Album 5, author: user1), Album(id: 6, title: Album 6, author: user1) ] func addAlbum(_ album: Album) { albums.insert(album, at: 0) } func removeAlbum(_ album: Album) { albums.removeAll(where: { $0 == album }) } } In my view, I inject it via @Environment and also keep some local state: @Environment(AlbumStore.self) var albumStore @State private var albumToAdd: Album? I derive a computed array that depends on both the environment store and local state: private var filteredAlbums: [Album] { let
2
0
220
Feb ’26
File Download Support in SwiftUI Native WebView (iOS 26+)
I am using the native SwiftUI WebView and WebPage APIs (iOS 26+) and would like to implement file download functionality using the native SwiftUI WebView. However, I have not been able to find any APIs equivalent to WKDownload. In WKWebView, the WKDownload API can be used to handle downloads. I am looking for a similar API or recommended approach in the native SwiftUI WebView that would allow downloading files. If anyone has guidance or suggestions on how to implement this, I would appreciate your help.
0
0
483
Feb ’26
Same Color in View and colorEffect shader argument produce different results
Opened feedback item FB21877364. Context I have the following Metal shader, which replaces one color with another. [[ stitchable ]] half4 recolor( float2 position, half4 currentColor, half4 from, half4 to ) { if (all(currentColor == from)) return to; return currentColor; } Given this SwiftUI view: let shader = ShaderLibrary.recolor(.color(.red), .color(.green)) Color.red .colorEffect(shader) I get a red rectangle instead of the expected green one. Note that this works on both dynamic and non-dynamic colors. Note that this sometimes works with some colors, which is very inconvenient when trying to figure out what's going on. Did I miss something? I would've expected the shader to work with colors the same way. Issue To really highlight the issue, here's another test case. I'll define #94877E in an Asset Catalog as example and check the RGB values using the Digital Color Meter app in Display native values mode. We'll use the following shader to determine how colorEffect receives colors: [[ stitchable ]
Topic: UI Frameworks SubTopic: SwiftUI
0
0
41
Feb ’26
Using a security-scoped bookmark with a symlink
I am developing an application on macOS in SwiftUI which exchanges files with other processes on a network. Some of these processes may be on Linux and write to a network drive. The files are refreshed at 10, 15 or 60 second intervals, and keep the same name. The software is supposed to run 24/7 and have persistent paths, so that on restart it does not need setting up. And it runs in the sandbox. I have got this working with macOS-only external processes by putting the exchange files in a fixed folder on the network storage and using security-scoped bookmarks to the file and or folder. But it doesn't work so well when one of the writing processes is a Linux process writing to its own storage. I can put a symlink in my fixed folder and if i select the folder and the symlink after each app restart, it works. but how can i make such a set-up persistent so it works after app restart without manual selection?
1
0
338
Feb ’26
Reply to Conditional Modifiers *if available*
Thanks for the post. My apologies as is hard to follow the code as the .cueStyle() is in else? so the if #available(macOS 26.0, *) { won’t apply there as far as I can tell. Can you post the code in a better way? There is a way I personally handle conditional modifiers in SwiftUI without duplicating large blocks of code. You can use an extension to conditionally apply the appropriate modifier based on the macOS version, while ensuring both modifiers conform to the same type. One approach is to define a protocol that both GlassCueStyle and CueStyle conform to, and then use that protocol to write a conditional modifier. protocol CueStyleModifier: ViewModifier { init(font: Font) } Maybe too over complicating that? Make sure both GlassCueStyle and CueStyle conform to the protocol. Create a conditional extension on View to apply the correct modifier. extension View { func applyCueStyle(font: Font = .system(size: 45)) -> some View { #if os(macOS) && targetEnvironment(macCatalyst) if #available(ma
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’26
Reply to Layout issue using .strokeBorder modifier
Thanks for the post, hard to see your code, will be better if you post it as code to copy and paste, did you defined the color of the strokeBoarder like? .overlay { Circle() .strokeBorder(.black, lineWidth: 4) } In my opinion and observations, this may happens when anti-aliasing is applied to the view’s edges which results in partially transparent pixels to smooth out the transition between the view and its background? To remedy this issue we can set the rasterizationScale modifier on the view that is getting the strokeBorder applied to match the screen scale and force Sharp edges. Let me know. Also looking for other SwiftUI developers opinion. Thanks, Albert Pascual
  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’26
Reply to Animation does not work with List, while works with ScrollView + ForEach
Some issue here. I have a MVP that outlines to issue easily: import SwiftUI struct ContentView: View { var body: some View { List { Element() Element() Element() } } } struct Element: View { @State var isOn: Bool = false var body: some View { VStack { HStack { Text(Hello, World!) Button(Toggle) { isOn.toggle() } } if isOn { Text(It's on!) .transition(.opacity) } } .animation(.default, value: isOn) } } #Preview { ContentView() .frame(width: 400) } When using LazyVStack instead of List, the animation works flawlessly.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’26
Reply to انشاء تطبيق جديد
Thanks for the post and happy you want to create a game. But your post does not provide specific questions we can answer. About the development environment you asked in your post if translate worked well: Development Environment: Xcode: This is Apple's integrated development environment (IDE). You'll need it to write and build your iOS or macOS app. Download it from the Mac App Store. Swift (Programming Language): Swift is Apple's preferred language for iOS/macOS development. It's modern, safe, and relatively easy to learn. UIKit or SwiftUI (User Interface Framework): UIKit: The traditional framework. Mature and highly documented. Might be more suitable if your team is already familiar with it. SwiftUI: Apple's newer, declarative UI framework. Easier to write cleaner and more maintainable code, especially for simple layouts. Consider this if you're starting fresh. We will focus on SwiftUI for this guide. Here are a few suggestions that might help it attract more attention: Provide m
Topic: Graphics & Games SubTopic: General Tags:
Feb ’26
Reply to ModelEntity position values are stale after world recenter (Crown long press)
That is weird! I haven't run into but maybe we have a new bug. Can you share any code that shows how you're reading the position data after recenter? Is there any event, notification, or callback that fires when the world is recentered due to a long press of the Crown button? Yes there is! Check out onWorldRecenter. It may not fix this issue, but you could use it to work around it. https://developer.apple.com/documentation/swiftui/view/onworldrecenter(action:)
Topic: Spatial Computing SubTopic: General Tags:
Feb ’26
Can TextField handle undo?
I'm struggling to understand whether TextField handles undo by itself, or how to properly handle it myself. In a macOS app with a SwiftUI lifecycle, in a DocumentGroup scene, I'm using both TextEditors and Textfields. The text editors handle undo out of the box, with undo coalescing. The text fields seem not to. However, on occasion, they do create undo points, leaving me confused as to what conditions are needed for that to happen. Is there a way to reliably get text fields to handle undo on their own? Or, how should I implement typing undo, including undo coalescing, manually?
Topic: UI Frameworks SubTopic: SwiftUI
9
0
242
Feb ’26
Reply to SwiftUI onChange fires twice when filtering data from @Observable store
This is a very interesting question, and you've done a great job of isolating the behavior and providing comparative examples. I’m not an expert on SwiftUI, wish I knew better, but that technology was always being really good at what you're seeing this double update with @Observable and @State, especially in conjunction with GeometryReader. When @Published properties change, they emit events. Views that are observing these properties (via @StateObject or @EnvironmentObject) then get scheduled for re-evaluation. The update cycle is generally more straightforward: state change -> event -> view re-render. filteredAlbums id: [3878E7A7-CDAB-444F-8B8C-263763735770, 1, 2, 3, 4, 5, 6] filteredAlbums id: [1, 2, 3, 4, 5, 6] You've triggered two state changes almost simultaneously: albumStore.addAlbum(newAlbum): This is a change to a property managed by your @Observable AlbumStore. albumToAdd = newAlbum: This is a change to a @State property within your view. Your carousel() function reads from albumStore
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Feb ’26
Reply to Can TextField handle undo?
To more clearly state my question, what I’m really asking is: how does SwiftUI’s TextField work with Undo? What are the conditions to making that work?
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Feb ’26
Showing 3D/AR content on multiple pages in iOS with RealityView
Hi. I'm trying to show 3D or AR content in multiple pages on an iOS app but I have found that if a RealityView is used earlier in a flow then future uses will never display the camera feed, even if those earlier uses do not use any spatial tracking. For example, in the following simplified view, the second page realityView will not display the camera feed even though the first view does not use it not start a tracking session. struct ContentView: View { var body: some View { NavigationStack { VStack { RealityView { content in content.camera = .virtual // showing model skipped for brevity } NavigationLink(Second Page) { RealityView { content in content.camera = .spatialTracking } } } } } } What is the way around this so that 3D content can be displayed in multiple places in the app without preventing AR content from working? I have also found the same problem when wrapping an ARView for use in SwiftUI.
Replies
0
Boosts
0
Views
524
Activity
Feb ’26
How to Integrate Apple Wallet with Custom FinTech Apps
Hi everyone, With the rapid growth of digital banking, payments, and AI-driven financial services, building secure and scalable FinTech apps on iOS has become more complex than ever. From handling sensitive user data to ensuring compliance and seamless performance, iOS developers face multiple technical challenges. Key areas that usually require deep expertise include: Apple Pay and Wallet integrations Secure authentication (Face ID / Touch ID / biometrics) Real-time transaction processing Core ML for financial predictions SwiftUI dashboards for financial analytics Data encryption and regulatory compliance https://www.nimbleappgenie.com At Nimble AppGenie, we’ve worked extensively as a FinTech app development expert, helping startups and enterprises design and build iOS financial applications that are secure, scalable, and user-centric. Our experience shows that the most successful fintech apps are those that balance strong security architecture with intuitive UX and performance optimization. I’m int
Replies
0
Boosts
0
Views
599
Activity
Feb ’26
SwiftUI onChange fires twice when filtering data from @Observable store
Hi all, I’m running into a “double update” effect in SwiftUI when using the @Observable with @State. I’m trying to understand whether this is expected behavior, a misuse on my side, or a potential bug. Setup I have an observable store using the Observation macro: @Observable class AlbumStore { var albums: [Album] = [ Album(id: 1, title: Album 1, author: user1), Album(id: 2, title: Album 2, author: user1), Album(id: 3, title: Album 3, author: user1), Album(id: 4, title: Album 4, author: user1), Album(id: 5, title: Album 5, author: user1), Album(id: 6, title: Album 6, author: user1) ] func addAlbum(_ album: Album) { albums.insert(album, at: 0) } func removeAlbum(_ album: Album) { albums.removeAll(where: { $0 == album }) } } In my view, I inject it via @Environment and also keep some local state: @Environment(AlbumStore.self) var albumStore @State private var albumToAdd: Album? I derive a computed array that depends on both the environment store and local state: private var filteredAlbums: [Album] { let
Replies
2
Boosts
0
Views
220
Activity
Feb ’26
File Download Support in SwiftUI Native WebView (iOS 26+)
I am using the native SwiftUI WebView and WebPage APIs (iOS 26+) and would like to implement file download functionality using the native SwiftUI WebView. However, I have not been able to find any APIs equivalent to WKDownload. In WKWebView, the WKDownload API can be used to handle downloads. I am looking for a similar API or recommended approach in the native SwiftUI WebView that would allow downloading files. If anyone has guidance or suggestions on how to implement this, I would appreciate your help.
Replies
0
Boosts
0
Views
483
Activity
Feb ’26
Same Color in View and colorEffect shader argument produce different results
Opened feedback item FB21877364. Context I have the following Metal shader, which replaces one color with another. [[ stitchable ]] half4 recolor( float2 position, half4 currentColor, half4 from, half4 to ) { if (all(currentColor == from)) return to; return currentColor; } Given this SwiftUI view: let shader = ShaderLibrary.recolor(.color(.red), .color(.green)) Color.red .colorEffect(shader) I get a red rectangle instead of the expected green one. Note that this works on both dynamic and non-dynamic colors. Note that this sometimes works with some colors, which is very inconvenient when trying to figure out what's going on. Did I miss something? I would've expected the shader to work with colors the same way. Issue To really highlight the issue, here's another test case. I'll define #94877E in an Asset Catalog as example and check the RGB values using the Digital Color Meter app in Display native values mode. We'll use the following shader to determine how colorEffect receives colors: [[ stitchable ]
Topic: UI Frameworks SubTopic: SwiftUI
Replies
0
Boosts
0
Views
41
Activity
Feb ’26
Using a security-scoped bookmark with a symlink
I am developing an application on macOS in SwiftUI which exchanges files with other processes on a network. Some of these processes may be on Linux and write to a network drive. The files are refreshed at 10, 15 or 60 second intervals, and keep the same name. The software is supposed to run 24/7 and have persistent paths, so that on restart it does not need setting up. And it runs in the sandbox. I have got this working with macOS-only external processes by putting the exchange files in a fixed folder on the network storage and using security-scoped bookmarks to the file and or folder. But it doesn't work so well when one of the writing processes is a Linux process writing to its own storage. I can put a symlink in my fixed folder and if i select the folder and the symlink after each app restart, it works. but how can i make such a set-up persistent so it works after app restart without manual selection?
Replies
1
Boosts
0
Views
338
Activity
Feb ’26
Reply to Conditional Modifiers *if available*
Thanks for the post. My apologies as is hard to follow the code as the .cueStyle() is in else? so the if #available(macOS 26.0, *) { won’t apply there as far as I can tell. Can you post the code in a better way? There is a way I personally handle conditional modifiers in SwiftUI without duplicating large blocks of code. You can use an extension to conditionally apply the appropriate modifier based on the macOS version, while ensuring both modifiers conform to the same type. One approach is to define a protocol that both GlassCueStyle and CueStyle conform to, and then use that protocol to write a conditional modifier. protocol CueStyleModifier: ViewModifier { init(font: Font) } Maybe too over complicating that? Make sure both GlassCueStyle and CueStyle conform to the protocol. Create a conditional extension on View to apply the correct modifier. extension View { func applyCueStyle(font: Font = .system(size: 45)) -> some View { #if os(macOS) && targetEnvironment(macCatalyst) if #available(ma
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Feb ’26
Reply to Layout issue using .strokeBorder modifier
Thanks for the post, hard to see your code, will be better if you post it as code to copy and paste, did you defined the color of the strokeBoarder like? .overlay { Circle() .strokeBorder(.black, lineWidth: 4) } In my opinion and observations, this may happens when anti-aliasing is applied to the view’s edges which results in partially transparent pixels to smooth out the transition between the view and its background? To remedy this issue we can set the rasterizationScale modifier on the view that is getting the strokeBorder applied to match the screen scale and force Sharp edges. Let me know. Also looking for other SwiftUI developers opinion. Thanks, Albert Pascual
  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Feb ’26
Reply to Animation does not work with List, while works with ScrollView + ForEach
Some issue here. I have a MVP that outlines to issue easily: import SwiftUI struct ContentView: View { var body: some View { List { Element() Element() Element() } } } struct Element: View { @State var isOn: Bool = false var body: some View { VStack { HStack { Text(Hello, World!) Button(Toggle) { isOn.toggle() } } if isOn { Text(It's on!) .transition(.opacity) } } .animation(.default, value: isOn) } } #Preview { ContentView() .frame(width: 400) } When using LazyVStack instead of List, the animation works flawlessly.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Feb ’26
Reply to انشاء تطبيق جديد
Thanks for the post and happy you want to create a game. But your post does not provide specific questions we can answer. About the development environment you asked in your post if translate worked well: Development Environment: Xcode: This is Apple's integrated development environment (IDE). You'll need it to write and build your iOS or macOS app. Download it from the Mac App Store. Swift (Programming Language): Swift is Apple's preferred language for iOS/macOS development. It's modern, safe, and relatively easy to learn. UIKit or SwiftUI (User Interface Framework): UIKit: The traditional framework. Mature and highly documented. Might be more suitable if your team is already familiar with it. SwiftUI: Apple's newer, declarative UI framework. Easier to write cleaner and more maintainable code, especially for simple layouts. Consider this if you're starting fresh. We will focus on SwiftUI for this guide. Here are a few suggestions that might help it attract more attention: Provide m
Topic: Graphics & Games SubTopic: General Tags:
Replies
Boosts
Views
Activity
Feb ’26
Reply to ModelEntity position values are stale after world recenter (Crown long press)
That is weird! I haven't run into but maybe we have a new bug. Can you share any code that shows how you're reading the position data after recenter? Is there any event, notification, or callback that fires when the world is recentered due to a long press of the Crown button? Yes there is! Check out onWorldRecenter. It may not fix this issue, but you could use it to work around it. https://developer.apple.com/documentation/swiftui/view/onworldrecenter(action:)
Topic: Spatial Computing SubTopic: General Tags:
Replies
Boosts
Views
Activity
Feb ’26
Reply to Can TextField handle undo?
Thanks for the tip! I am using SwiftUI, however, so its's the SwiftUI TextEditor and TextField views that I'm trying to understand.
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Feb ’26
Can TextField handle undo?
I'm struggling to understand whether TextField handles undo by itself, or how to properly handle it myself. In a macOS app with a SwiftUI lifecycle, in a DocumentGroup scene, I'm using both TextEditors and Textfields. The text editors handle undo out of the box, with undo coalescing. The text fields seem not to. However, on occasion, they do create undo points, leaving me confused as to what conditions are needed for that to happen. Is there a way to reliably get text fields to handle undo on their own? Or, how should I implement typing undo, including undo coalescing, manually?
Topic: UI Frameworks SubTopic: SwiftUI
Replies
9
Boosts
0
Views
242
Activity
Feb ’26