Explore the various UI frameworks available for building app interfaces. Discuss the use cases for different frameworks, share best practices, and get help with specific framework-related questions.

All subtopics
Posts under UI Frameworks topic

Post

Replies

Boosts

Views

Activity

ObservableObjects get retained after a TextField is focused
When presenting a SwiftUI sheet containing ObservableObject's injected using environmentObject(_) modifier, the objects are unexpectedly retained after the sheet is dismissed if a TextField within the sheet gains focus or is edited. This issue occurs on iOS and iPadOS (on macOS the objects are always released), observable both in the simulator and on physical devices, and happens even when the view does not explicitly reference these environment objects, and the TextField's content isn't bound to them. Expected Results: When the sheet is dismissed, all environment objects passed to the sheet’s content view should be released (deinitialized), regardless of whether the TextField was focused or edited. Actual Results: If the TextField was focused or edited, environment objects (ObservableA and ObservableB) are retained after the sheet is dismissed. They are not deinitialized as expected, leading to unintended retention. Interestingly, previously retained copies of these environment objects, if any, are released precisely at the moment the TextField becomes focused on subsequent presentations, indicating an inconsistent lifecycle behavior. I have filed an issue FB17226970 Sample Code Below is a sample code that consistently shows the issue on iOS 18.3+. Steps to Reproduce: Run the attached SwiftUI sample. Tap the button labeled “Show Sheet” to present a sheet. Tap on the TextField to focus or begin editing. Dismiss the sheet by dragging it down or by other dismissal methods (e.g., tapping outside on iPadOS). import SwiftUI struct ContentView: View { @State private var showSheet: Bool = false var body: some View { VStack { Button("Show Sheet") { showSheet = true } } .sheet(isPresented: $showSheet) { SheetContentView() .environmentObject(ObservableA()) .environmentObject(ObservableB()) } } } struct SheetContentView: View { @State private var text: String = "" var body: some View { TextField("Select to retain observable objects", text: $text) .textFieldStyle(.roundedBorder) } } final class ObservableA: ObservableObject { init() { print(type(of: self), #function) } deinit { print(type(of: self), #function) } } final class ObservableB: ObservableObject { init() { print(type(of: self), #function) } deinit { print(type(of: self), #function) } } #Preview { ContentView() }
2
0
191
Apr ’25
Disable collapsing Sidebar/NavigationSplitView
I want to keep the sidebar fixed in NavigationSplitView. I don’t want the user to be able to open or close the sidebar. I removed the toggle button, but I still couldn’t make the sidebar stay fixed. It can still be closed using Cmd + Alt + S or by dragging. What I want is just to disable the resize feature of the sidebar. Isn’t it possible with SwiftUI? NavigationSplitView is kind of blackhole :) LeftSidebarView() .environmentObject(detailView) .toolbar(removing: .sidebarToggle) .navigationSplitViewColumnWidth(240)
1
0
223
Mar ’25
CarPlay Question
Why is there no option as a CarPlay developer to enable the creation of an App to track and enter your car's maintenance records? I know the pat reply would be Apple doesn't want you to do this while car is in motion. But I would normally do this while parked at the dealership or other service provider no?
1
0
302
Mar ’25
Vibrancy effect not applied to context menu UIImages rendered in template mode
Our Apple TV provides UIImages with renderingMode forced to .alwaysTemplate (the images are also configured with "Render As" to "Template image" in the Asset catalog) to UIActions as UIMenuElement when building a UICollectionView UIContextMenuConfiguration. Problem: these images are not displayed with vibrancy effect by the system. The issue does not occur with system images (SVG from SF Catalog). Here is a screenshot showing the issue with custom images ("Trailer" and "Remove from favourites"): I don't know the underlying implementation of the context menu items image but UIImageView already implements the tintColorDidChange() method and the vibrancy should work if the UIImage is rendered as template. According to my tests, the vibrancy is correctly applied when using Symbols sets instead of Images sets but I understand that custom images rendered as template should support it as-well, shouldn't they?
2
0
201
Mar ’25
UIScrollView in UIViewControllerRepresentable - UI freezes when content touches bottom SafeArea
The SwiftUI ScrollView lacks some features I need and so I created a custom MyScrollView based on UIScrollView wrapped within a UIViewControllerRepresentable. While this works fine in general I know came across a very strange problem: When MyScrollView is used in a sheet and its content touches bottom SafeArea, the UI freezes as soon as the should be displayed. The code below shows the problem as well in preview as on the simulator and on devices. Please note that the code is tuned do the display size of an iPhone 16 Pro. When running on different devices one might need to adjust height of the Color.yellow. In the demo code the UI freezes if the Color.yellow has a height between 738 to 771 pixels. Every other height is fine. Is there something wrong with my implementation of MyScrollView? When using ScrollView instead, everything works fine. Code: struct ContentView: View { @State private var showSheet: Bool = false var body: some View { ZStack { Button("Show Sheet") { showSheet = true } } .sheet(isPresented: $showSheet) { VStack { Text("Some Header Content") MyScrollView { VStack { Color.yellow //.frame(height: 737) // works .frame(height: 738) // does NOT works // ... //.frame(height: 771) // does NOT works //.frame(height: 772) // works } } .ignoresSafeArea() } } } } struct MyScrollView<Content: View>: UIViewControllerRepresentable { let content: Content init(@ViewBuilder content: () -> Content) { self.content = content() } func makeUIViewController(context: Context) -> UIViewController { let scrollViewVC = UIViewController() scrollViewVC.view.backgroundColor = .clear let scrollView = UIScrollView() scrollView.backgroundColor = .clear let contentVC = UIHostingController(rootView: self.content) contentVC.view.backgroundColor = .clear context.coordinator.contentVC = contentVC context.coordinator.scrollView = scrollView scrollView.translatesAutoresizingMaskIntoConstraints = false scrollViewVC.view.addSubview(scrollView) NSLayoutConstraint.activate([ scrollView.topAnchor.constraint(equalTo: scrollViewVC.view.topAnchor), scrollView.bottomAnchor.constraint(equalTo: scrollViewVC.view.bottomAnchor), scrollView.leadingAnchor.constraint(equalTo: scrollViewVC.view.leadingAnchor), scrollView.trailingAnchor.constraint(equalTo: scrollViewVC.view.trailingAnchor) ]) contentVC.willMove(toParent: scrollViewVC) scrollViewVC.addChild(contentVC) contentVC.view.translatesAutoresizingMaskIntoConstraints = false scrollView.addSubview(contentVC.view) NSLayoutConstraint.activate([ contentVC.view.topAnchor.constraint(equalTo: scrollView.contentLayoutGuide.topAnchor), contentVC.view.bottomAnchor.constraint(equalTo: scrollView.contentLayoutGuide.bottomAnchor), contentVC.view.leadingAnchor.constraint(equalTo: scrollView.contentLayoutGuide.leadingAnchor), contentVC.view.trailingAnchor.constraint(equalTo: scrollView.contentLayoutGuide.trailingAnchor), contentVC.view.widthAnchor.constraint(equalTo: scrollView.frameLayoutGuide.widthAnchor) ]) contentVC.didMove(toParent: scrollViewVC) return scrollViewVC } func updateUIViewController(_ uiViewController: UIViewController, context: Context) { context.coordinator.contentVC?.rootView = content } func makeCoordinator() -> Coordinator { return Coordinator() } class Coordinator { var contentVC: UIHostingController<Content>? var scrollView: UIScrollView? init() { //... } } } #Preview { ContentView() }
Topic: UI Frameworks SubTopic: SwiftUI
2
0
112
Apr ’25
drag a modelEntity inside an Immersive space and track position
Goal : Drag a sphere across the room and track it's position Problem: The gesture seems to have no effect on the sphere ModelEntity. I don't know how to properly attach the gesture to the ModelEntity. Any help is great. Thank you import SwiftUI import RealityKit import RealityKitContent import Foundation @main struct testApp: App { @State var immersionStyle:ImmersionStyle = .mixed var body: some Scene { ImmersiveSpace { ContentView() } .immersionStyle(selection: $immersionStyle, in: .mixed, .full, .progressive) } } struct ContentView: View { @State private var lastPosition: SIMD3<Float>? = nil @State var subscription: EventSubscription? @State private var isDragging: Bool = false var sphere: ModelEntity { let mesh = MeshResource.generateSphere(radius: 0.05) let material = SimpleMaterial(color: .blue, isMetallic: false) let entity = ModelEntity(mesh: mesh, materials: [material]) entity.generateCollisionShapes(recursive: true) return entity } var drag: some Gesture { DragGesture() .targetedToEntity(sphere) .onChanged { _ in self.isDragging = true } .onEnded { _ in self.isDragging = false } } var body: some View { Text("Hello, World!") RealityView { content in //1. Anchor Entity let anchor = AnchorEntity(world: SIMD3<Float>(0, 0, -1)) let ball = sphere //1.2 add component to ball ball.components.set(InputTargetComponent()) //2. add anchor to sphere anchor.addChild(ball) content.add(anchor) subscription = content.subscribe(to: SceneEvents.Update.self) { event in let currentPosition = ball.position(relativeTo: nil) if let last = lastPosition, last != currentPosition { print("Sphere moved from \(last) to \(currentPosition)") } lastPosition = currentPosition } } .gesture(drag) } }
0
0
67
Apr ’25
Inconsistent ornament scale
I am developing an application which make use of 2 ornaments anchored to a volumetric window, one used a toolbar and one to display different views. The problem I am facing consistently is that the ornaments seems to scale up or down after moving the volume using the OS handle or starting a GroupActivity session. This first image shows the ornaments as soon as I started the app, no dragging nor group activities: This second images shows them as soon as I join a group activity session: The map, which might seem smaller, has not been touched and has always the same scale. In this last image I had just dragged the entire volume using the OS toolbar, resulting in the ornaments scaling down: This is how the volume and the ornaments are declared: WindowGroup(id: "CityVolume") { let cityVM = CityViewModel(volumeSize: CityView.initialVolumeSize) CityView(cityVM: cityVM) .ornament(attachmentAnchor: .scene(.bottomFront)) { HStack { TourismChartsButton() LandmarksListButton() CenterMapButton() ToggleImmersiveSpaceButton() TrafficDataButton() BusLinesButton() } .padding() .offset(z: 10) .rotation3DEffect(Angle(degrees: 15), axis: (x: 1.0, y: 0.0, z: 0.0)) } .ornament(attachmentAnchor: .scene(.back)) { ZStack { if AppModel.Instance.tourismVM.isChartViewVisible { TourismChartsView() } if AppModel.Instance.busLinesVM.isDataViewEnabled { BusLineView() } } } .task(observeGroupActivity) .onAppear { appModel.cityVM = cityVM } } .windowStyle(.volumetric) .windowResizability(.contentSize) .volumeWorldAlignment(.gravityAligned) .defaultSize(CityView.initialVolumeSize, in: .meters) It happens also without starting a SharePlay session, but not as frequently as during SharePlay. Experienced the same behaviour with toolbars. Am I doing something wrong with how I created the ornaments? Am I missing something?
0
0
104
Apr ’25
Widgets and App extensions
Hi, I have few questions regarding the widgets. I would like to know whether widget and app extensions are same ? This link(https://developer.apple.com/app-extensions/) says widget is type of app extension but I am not quite sure as few link in web says they are different. so need to confirm here :) Can a widget share same bundle id as the main app ? so basically can we use the same provisioning profile as the main app? If we use the same bundle id and provisioning profile, will there be any issue during the app store submission process.?
1
0
680
Mar ’25
Food Truck Sample animation issue from Table Component
Hi! I'm seeing some weird animation issues building the Food Truck sample application.^1 I'm running from macOS 15.4 and Xcode 16.3. I'm building the Food Truck application for macOS. I'm not focusing on iOS for now. The FoodTruckModel adds new Order values with an animation: // FoodTruckModel.swift withAnimation(.spring(response: 0.4, dampingFraction: 1)) { self.orders.append(orderGenerator.generateOrder(number: orders.count + 1, date: .now, generator: &generator)) } This then animates the OrdersTable when new Order values are added. Here is a small change to OrdersTable: // OrdersTable.swift - @State private var sortOrder = [KeyPathComparator(\Order.status, order: .reverse)] + @State private var sortOrder = [KeyPathComparator(\Order.creationDate, order: .reverse)] Running the app now inserts new Order values at the top. The problem is I seem to be seeing some weird animation issues here. It seems that as soon as the new Order comes in there is some kind of weird glitch where it appears as if part the animation is coming from the side instead of down from the top: What's then more weird is that if I seem to affect the state of the Table in any way then the next Order comes in with perfect animation. Scrolling the Table fixes the animation. Changing the creationData sort order from reverse to forward and back to reverse fixes the animation. Any ideas? Is there something about how the Food Truck product is built that would cause this to happen? Is this an underlying issue in the SwiftUI infra?
0
0
69
Apr ’25
Trouble using MKAnnotation on a MKMapView
Hi everyone, i'im having troubles using Annotation on a Map View. I have a a core data model called Location that conforms to NSManagedObject from CoreData and MKAnnotation form MapKit, and i'm trying to add an array of Location to a MKMview instance in a UIViewController class, by doing somethhing like this: mapView.addAnnotation(locations), but xcode compliants with a strange error which says Argument type '[Location]' does not conform to expected type 'MKAnnotation'. it's strange to me because my Location class conforms to MKAnnotation protocol and i implemented the protocol's methods (coordinate, title, subtitle). Please can anyone help me how to fix this issues. Thank you all
Topic: UI Frameworks SubTopic: UIKit Tags:
2
0
179
Mar ’25
Library not loaded: /System/Library/Frameworks/SwiftUICore.framework/SwiftUICore
Hello. I'm building an iOS application that builds a framework named Design.framework using Xcode 16.1. When I launch my application on iOS 17.X, i get the following runtime error dyld[47899]: Library not loaded: /System/Library/Frameworks/SwiftUICore.framework/SwiftUICore Referenced from: <E625A246-E36B-351A-B077-CC38BAB5E07B> /Users/v/Library/Developer/Xcode/DerivedData/iScribd-bexojbdreldwkvbpzioqueldnvng/Build/Products/Debug_AppStore-iphonesimulator/Design.framework/Design Reason: tried: '/Users/v/Library/Developer/Xcode/DerivedData/iScribd-bexojbdreldwkvbpzioqueldnvng/Build/Products/Debug_AppStore-watchsimulator/SwiftUICore.framework/SwiftUICore' (no such file), '/Users/v/Library/Developer/Xcode/DerivedData/iScribd-bexojbdreldwkvbpzioqueldnvng/Build/Products/Debug_AppStore-iphonesimulator/SwiftUICore.framework/SwiftUICore' (no such file), '/Users/v/Library/Developer/Xcode/DerivedData/iScribd-bexojbdreldwkvbpzioqueldnvng/Build/Products/Debug_AppStore-watchsimulator/PackageFrameworks/SwiftUICore.framework/SwiftUICore' (no such file), '/Users/v/Library/Developer/Xcode/DerivedData/iScribd-bexojbdreldwkvbpzioqueldnvng/Build/Products/Debug_AppStore-iphonesimulator/PackageFrameworks/SwiftUICore.framework/SwiftUICore' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_21C62/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.2.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/SwiftUICore.framework/SwiftUICore' (no such file), '/System/Library/Frameworks/SwiftUICore.framework/SwiftUICore' (no such file, not in dyld cache), '/Library/Developer/CoreSimulator/Volumes/iOS_21C62/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.2.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/SwiftUICore.framework/SwiftUICore' (no such file) This error does not happen on iOS 18+. When i run dyld_info Design.framework/Design, i see that there is indeed a dependency on SwiftUICore.framework Design.framework/Design [arm64]: -platform: platform minOS sdk iOS-simulator 16.0 18.1 -uuid: 09880F25-DC86-3D8E-BCAE-1A283508D879 -segments: load-offset segment section sect-size seg-size max-prot init-prot 0x00000000 __TEXT 416KB r.x 0x00000000 __TEXT 416KB r.x 0x0000543C __text 355508 0x0005C0F0 __stubs 3168 0x0005CD50 __objc_methlist 32 0x0005CD70 __const 8296 0x0005EDD8 __swift5_typeref 15820 0x00062BB0 __cstring 6885 0x00064698 __constg_swiftt 2804 0x0006518C __swift5_builtin 40 0x000651C0 __swift5_reflstr 2952 0x00065D48 __swift5_assocty 816 0x00066078 __objc_methname 299 0x000661A4 __swift5_proto 368 0x00066314 __swift5_types 280 0x0006642C __swift5_fieldmd 3688 0x00067294 __swift5_protos 8 0x0006729C __swift5_capture 244 0x00067390 __unwind_info 2296 0x00067C88 __eh_frame 888 0x00068000 __DATA_CONST 16KB rw. 0x00068000 __DATA_CONST 16KB rw. 0x00068000 __got 3704 0x00068E78 __const 6864 0x0006A948 __objc_classlist 40 0x0006A970 __objc_imageinfo 8 0x0006C000 __DATA 32KB rw. 0x0006C000 __DATA 32KB rw. 0x0006C000 __objc_const 792 0x0006C318 __objc_selrefs 96 0x0006C378 __objc_classrefs 48 0x0006C3A8 __objc_data 208 0x0006C478 __data 4136 0x0006D4A0 __bss 12784 0x00070690 __common 4592 -linked_dylibs: attributes load path @rpath/CommonTools.framework/CommonTools /System/Library/Frameworks/Foundation.framework/Foundation /usr/lib/libobjc.A.dylib /usr/lib/libSystem.B.dylib /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation /System/Library/Frameworks/CoreGraphics.framework/CoreGraphics /System/Library/Frameworks/CoreText.framework/CoreText weak-link /System/Library/Frameworks/DeveloperToolsSupport.framework/DeveloperToolsSupport /System/Library/Frameworks/SwiftUI.framework/SwiftUI /System/Library/Frameworks/SwiftUICore.framework/SwiftUICore /System/Library/Frameworks/UIKit.framework/UIKit /usr/lib/swift/libswiftCore.dylib weak-link /usr/lib/swift/libswiftCoreAudio.dylib /usr/lib/swift/libswiftCoreFoundation.dylib weak-link /usr/lib/swift/libswiftCoreImage.dylib weak-link /usr/lib/swift/libswiftCoreMedia.dylib weak-link /usr/lib/swift/libswiftDarwin.dylib weak-link /usr/lib/swift/libswiftDataDetection.dylib weak-link /usr/lib/swift/libswiftDispatch.dylib weak-link /usr/lib/swift/libswiftFileProvider.dylib weak-link /usr/lib/swift/libswiftMetal.dylib weak-link /usr/lib/swift/libswiftOSLog.dylib /usr/lib/swift/libswiftObjectiveC.dylib weak-link /usr/lib/swift/libswiftQuartzCore.dylib weak-link /usr/lib/swift/libswiftSpatial.dylib weak-link /usr/lib/swift/libswiftUniformTypeIdentifiers.dylib weak-link /usr/lib/swift/libswiftXPC.dylib /usr/lib/swift/libswift_Concurrency.dylib weak-link /usr/lib/swift/libswiftos.dylib weak-link /usr/lib/swift/libswiftsimd.dylib weak-link /usr/lib/swift/libswiftUIKit.dylib I can add a -weak_framework SwiftUICore to "Other Linker Flags" in my Design.framework Build Settings, and that will solve my problem, but I'd like to know what prompts my Design.framework to depend on SwiftUICore despite having a minimum set to iOS 16? And how am I supposed to handle devices prior to iOS 18 which do not have this library? is adding the linker flag the right way forward?
Topic: UI Frameworks SubTopic: SwiftUI
5
0
1.5k
Apr ’25
Serious Bug with SwiftUI/ImagePicker/Camera + workaround
I was doing an app which had several "camera" buttons each one dedicated to taking/storing/reviewing/deleting an image associated with a variable URL but what should have been a simple no brainer turned out to be a programming nightmare. To cut a long story short there is a bug in the sheet handling wherebye even tho you have separate instance for each button the camera/picker cylcles sequentially thru the stack of instances for any action finally always placing the image in the first URL. Working with myself debugging, all major AIs (Grok, Claude, Gemini and Perplexity) after 4 x 12hr+ days we finally managed to crack a solution. What follows is Groks interpretation (note it misses the earlier problem of instance cycling!!) ... You can follow the discussion here: https://x.com/i/grok/share/KHeaUPladURmbFq5qy9W506er but be warned its long a detailed but if you are having problems then read ... **Bug Report: Race Conditions with UIImagePickerController in SwiftUI Sheet ** Environment: SwiftUI, iOS 17.7.5 Device: iPad Pro (12.9-inch, 2nd generation) Xcode Version: [Insert your Xcode version] Date: March 30, 2025 **Issue 1: Multiple Instances of UIImagePickerController Spawned After Dismissal ** Description: When using a UIImagePickerController wrapped in a UIViewControllerRepresentable and presented via a SwiftUI .sheet, selecting "Use Photo" resulted in multiple unintended instances of the picker being initialized and presented. The console logs showed repeated "Camera initialized" and "Camera sheet appeared" messages (e.g., multiple <UIImagePickerController: 0x...> instances) after the initial dismissal, despite the sheet being dismissed programmatically. Reproduction Steps: Create a SwiftUI view with a button that sets a @State variable showCamera to true. Present a UIImagePickerController via .sheet(isPresented: $showCamera). Update a @Binding variable (e.g., photoLocation: URL?) in imagePickerController(_:didFinishPickingMediaWithInfo:) after saving the image. Dismiss the picker with picker.dismiss(animated: true) and presentationMode.wrappedValue.dismiss(). Observe that updating the @Binding variable triggers a view re-render, causing the .sheet to re-present multiple times before finally staying dismissed. Root Cause: A race condition occurred between the view update (triggered by changing photoLocation) and the dismissal of the picker. During the re-render, showCamera remained true momentarily, causing the .sheet modifier to re-evaluate and spawn new picker instances before the onDismiss closure could reset showCamera to false. The fix involved delaying the @Binding update (photoLocation) until after the picker and sheet were fully dismissed, ensuring showCamera was reset to false before the view re-rendered: Introduced an onPhotoPicked: (URL) -> Void closure to decouple the photoLocation update from the dismissal timing. Modified the coordinator to call onPhotoPicked and reset showCamera before initiating dismissal:swift Issue 2: Single Unintended Picker Reopen After Initial Fix Description: After addressing the multiple-instance issue, a single unintended reopen of the picker persisted. The logs showed one additional "Camera initialized" and "Camera sheet appeared" after "Use Photo," before the final dismissal. Reproduction Steps: Reproduction Steps: Use the initial fix with onPhotoPicked and delayed photoLocation update. Take a photo and select "Use Photo." Observe one extra picker instance appearing briefly before dismissal completes. Root Cause: The @Binding update (photoLocation) was still occurring too early in the dismissal sequence. Although delayed until after picker.dismiss, the view re-render happened while showCamera was still true during the dismissal animation, causing the .sheet to re-present once before onDismiss reset showCamera. Resolution: The fix ensured showCamera was set to false before the picker dismissal animation began, preventing the .sheet from re-evaluating during the transition: Moved the dismissCamera() call (which sets showCamera to false) into the onPhotoPicked callback, executed before picker.dismiss: CameraView( photoLocation: $photoLocation, storeDirectory: storeDirectory, onPhotoPicked: { url in print("Photo picked callback for \(id), setting photoLocation: \(url)") self.photoLocation = url self.cameraState.dismissCamera() // Sets showCamera to false first } ) Kept the dismissal sequence in the coordinator: DispatchQueue.main.async { self.parent.onPhotoPicked(fileURL) picker.dismiss(animated: true) { self.parent.presentationMode.wrappedValue.dismiss() } } This synchronized the state change with the dismissal, ensuring showCamera was false before the view re-rendered, eliminating the single reopen. Request: Could the SwiftUI team clarify if this behavior is expected, or consider improving the .sheet modifier to better handle state transitions during UIKit controller dismissal? A more robust bridge between SwiftUI’s declarative state and UIKit’s imperative lifecycle could prevent such race conditions.
Topic: UI Frameworks SubTopic: UIKit Tags:
1
0
93
Mar ’25
Hover effect in Custom UIKit Views
I am adapting my custom UI Framework for visionOS, and I'm wondering if it is going to be possible to detect hover over different UI elements within my view. The UI Framework draws to a Metal layer in a UIView. I don't currently support uihovergesturerecognizer on the view but I guess this wouldn't help, since you don't get coordinates. I can imagine an unpleasant solution might be to add invisible UIControls for each of my custom controls that are drawn in my own framework.
1
0
62
Apr ’25
Release Build Configuration as Release Fails Preview
I have a simple SwiftUI project with two basic build configurations (Debug, Release) as shown below. I now choose Build > Scheme > Edit Scheme under Product and select Release as the current build configuration as shown below. And the Preview canvas exhibit errors. If I click on the Diagnostics button, it says under PREVIEW UPDATE ERROR OptimizationLevelError: not building -Onone ”BuildSchemeCrazyDaughter.app” needs -Onone Swift optimization level to use previews (current setting is -O) What does that mean and why don't I get the preview for the Release build configuration? Thanks.
1
0
204
Mar ’25
Siri Intent Dialog with custom SwiftUIView not responding to buttons with intent
I have created an AppIntent and added it to shortcuts to be able to read by Siri. When I say the phrase, the Siri intent dialog appears just fine. I have added a custom SwiftUI View inside Siri dialog box with 2 buttons with intents. The callback or handling of those buttons is not working when initiated via Siri. It works fine when I initiate it in shortcuts. I tried using the UIButton without the intent action as well but it did not work. Here is the code. static let title: LocalizedStringResource = "My Custom Intent" static var openAppWhenRun: Bool = false @MainActor func perform() async throws -> some ShowsSnippetView & ProvidesDialog { return .result(dialog: "Here are the details of your order"), content: { OrderDetailsView() } } struct OrderDetailsView { var body: some View { HStack { if #available(iOS 17.0, *) { Button(intent: ModifyOrderIntent(), label : { Text("Modify Order") }) Button(intent: CancelOrderIntent(), label : { Text("Cancel Order") }) } } } } struct ModifyOrderIntent: AppIntent { static let title: LocalizedStringResource = "Modify Order" static var openAppWhenRun: Bool = true @MainActor func perform() async throws -> some OpensIntent { // performs the deeplinking to app to a certain page to modify the order } } struct CancelOrderIntent: AppIntent { static let title: LocalizedStringResource = "Cancel Order" static var openAppWhenRun: Bool = true @MainActor func perform() async throws -> some OpensIntent { // performs the deeplinking to app to a certain page to cancel the order } } Button(action: { if let url = URL(string: "myap://open-order") { UIApplication.shared.open(url) } }
0
0
366
Mar ’25
[iOS 18 Only] Intermittent Crash at completeTransition in Custom Navigation Animation (Firebase Crashlytics)
Hi everyone, I'm encountering an intermittent crash on iOS 18 only (not reproducible locally, reported in Firebase Crashlytics) at transitionContext.completeTransition(!transitionContext.transitionWasCancelled) within my custom UIViewControllerAnimatedTransitioning. The same code runs fine on iOS 16 and 17 (no Crashlytics report for those iOS version) Here's the crash log: Crashed: com.apple.main-thread 0 libswiftCore.dylib 0x4391f0 swift_getObjectType + 40 1 ROOM 0x490c48 ItemDetailAnimator.navigationController(_:animationControllerFor:from:to:) + 47 (ItemDetailAnimator.swift:47) 2 ROOM 0x490f3c @objc ItemDetailAnimator.navigationController(_:animationControllerFor:from:to:) + 92 (<compiler-generated>:92) 3 UIKitCore 0xa2d7a4 -[UINavigationController _customTransitionController:] + 516 4 UIKitCore 0x2e51dc -[UINavigationController _immediatelyApplyViewControllers:transition:animated:operation:] + 2620 5 UIKitCore 0x1541d4 __94-[UINavigationController _applyViewControllers:transition:animated:operation:rescheduleBlock:]_block_invoke + 100 6 UIKitCore 0x150768 -[UINavigationController _applyViewControllers:transition:animated:operation:rescheduleBlock:] + 776 7 UIKitCore 0x2e7e44 -[UINavigationController pushViewController:transition:forceImmediate:] + 544 8 UIKitCore 0x2e4230 -[UINavigationController pushViewController:animated:] + 444 9 ROOM 0x66cb04 UINavigationController.pushViewController(_:animated:completion:) + 185 (UINavigationController+Room.swift:185) 10 ROOM 0x8cef4c ItemDetailCoordinator.start(animated:completion:) + 99 (ItemDetailCoordinator.swift:99) 11 ROOM 0xc6c95c protocol witness for Coordinator.start(animated:completion:) in conformance BaseCoordinator + 24 (<compiler-generated>:24) 12 ROOM 0x8ca520 AppCoordinator.startCoordinator(_:url:reference:animated:completion:) + 729 (AppCoordinator.swift:729) 13 ROOM 0x8cb248 protocol witness for URLSupportCoordinatorOpener.startCoordinator(_:url:reference:animated:completion:) in conformance AppCoordinator + 48 (<compiler-generated>:48) 14 ROOM 0xd6166c URLSupportCoordinatorOpener<>.open(url:openingController:reference:animated:completion:) + 118 (URLSupportedCoordinator.swift:118) 15 ROOM 0xc56038 RRAppDelegate.handleURL(url:completion:) + 588 (RRAppDelegate.swift:588) 16 ROOM 0xc502d0 RRAppDelegate.applicationDidBecomeActive(_:) + 330 (RRAppDelegate.swift:330) 17 ROOM 0xc5041c @objc RRAppDelegate.applicationDidBecomeActive(_:) + 52 (<compiler-generated>:52) 18 UIKitCore 0x1fb048 -[UIApplication _stopDeactivatingForReason:] + 1368 My animateTransition code is: ```func animateTransition( using transitionContext: UIViewControllerContextTransitioning) { guard let (fromView, toView, fromVC, toVC) = filterTargets(context: transitionContext) else { transitionContext.cancelInteractiveTransition() transitionContext.completeTransition(false) return } let containerView = transitionContext.containerView toView.frame = transitionContext.finalFrame(for: toVC) guard let targetView = fromVC.animationTargetView, let fromFrame = fromVC.animationTargetFrame, let toFrame = toVC.animationTargetFrame else { containerView.insertSubview(toView, aboveSubview: fromView) toView.frame = transitionContext.finalFrame(for: toVC) transitionContext.completeTransition(true) return } let newFromFrame = fromView.convert(fromFrame, to: containerView) let tempImageView: UIImageView if let target = targetView as? UIImageView, let image = targetImage ?? target.image, image.size.height != 0, target.frame.height != 0, image.size.width / image.size.height != target.frame.width / target.frame.height { targetImage = image tempImageView = UIImageView(image: image) tempImageView.frame = newFromFrame tempImageView.contentMode = .scaleAspectFit } else { tempImageView = targetView.room.asImageView() tempImageView.frame = newFromFrame } targetView.isHidden = true let tempFromView = containerView.room.asImageView() targetView.isHidden = false let tempHideView = UIView() containerView.addSubview(tempFromView) containerView.insertSubview(toView, aboveSubview: tempFromView) tempHideView.backgroundColor = .white toView.addSubview(tempHideView) containerView.addSubview(tempImageView) //Minus with item detail view y position //Need to minus navigation bar height of item detail view var tempHideViewFrame = toFrame tempHideViewFrame.origin.y -= toView.frame.origin.y tempHideView.frame = tempHideViewFrame let duration = transitionDuration(using: transitionContext) toView.alpha = 0 UIView.animate(withDuration: duration * 0.5, delay: duration * 0.5, options: .curveLinear, animations: { toView.alpha = 1 }) let scale: CGFloat = toFrame.width / newFromFrame.width let newFrame = CGRect( x: toFrame.minX - newFromFrame.minX * scale, y: toFrame.minY - newFromFrame.minY * scale, width: tempFromView.frame.size.width * scale, height: tempFromView.frame.size.height * scale) UIView.animate(withDuration: duration, delay: 0.0, options: [.curveEaseInOut], animations: { tempFromView.frame = newFrame tempImageView.frame = toFrame }, completion: { _ in tempHideView.removeFromSuperview() tempFromView.removeFromSuperview() tempImageView.removeFromSuperview() transitionContext.completeTransition(!transitionContext.transitionWasCancelled) }) }
4
0
217
Apr ’25
GPS Track Navigation with MapKit?
I want to create a MKRoute from a list of MKMapPoints or coordinates. But apparently MKRoute can only be generated from a MKDirections request from Apple's servers. The primary use of my app will be activities (eg hiking) in the back country where (1) a network connection likely won't be available and (2) there likely will not be a trail in Apple's map network. For example I want to provide navigation for following a recorded GPS track or my only MKPolyLines. Note that I am required to use MapKit (3rd party map SDKs are not an option for a number of reasons). It feels like a huge missed opportunity if MapKit doesn't allow Routes to be created from a predetermined list of coordinates. Does anyone know of any solutions for this problem either somehow creating a MKRoute from a list of coordinates or a 3rd party library? I've searched but haven't had any luck finding a solution. It seems like something like this must exist so I thought I'd ask.
Topic: UI Frameworks SubTopic: UIKit Tags:
2
0
77
Apr ’25
UITextView in SwiftUI Not Scrolling to Position When Becoming First Responder
I'm implementing a custom text editor in SwiftUI using a UITextView wrapped in a UIViewRepresentable. The text editor works for basic text entry, but I'm encountering an issue with scrolling behavior. When the UITextView becomes the first responder (when tapped), the parent ScrollView doesn't automatically scroll to make the text view visible. Instead, the scroll position jumps to the last known position (scrolls to a different text view that was previously focused). Here's my implementation reduced to the minimum: struct SpacedTextEditor: View { @Binding var text: String var body: some View { MinimalEditor(text: $text) } } private struct MinimalEditor: UIViewRepresentable { @Binding var text: String func makeUIView(context: Context) -> UITextView { let textView = UITextView() textView.backgroundColor = .clear textView.delegate = context.coordinator textView.isScrollEnabled = false textView.text = text return textView } func updateUIView(_ textView: UITextView, context _: Context) { if textView.text != text { textView.text = text } } func makeCoordinator() -> Coordinator { Coordinator(text: $text) } class Coordinator: NSObject, UITextViewDelegate { var text: Binding<String> init(text: Binding<String>) { self.text = text } func textViewDidChange(_ textView: UITextView) { text.wrappedValue = textView.text } } } The text editor is placed inside a ScrollView in my parent view. How can I ensure that when a user taps on the text editor, the ScrollView properly scrolls to make it fully visible or at least it doesn't jump to where the textfield is not even visible? I need to use a custom textfield because I need to be able to modify the space between lines, and I didn't find a way to do this using the swiftUI component.
Topic: UI Frameworks SubTopic: SwiftUI
1
0
105
Mar ’25
app crashing in iPad Only
app crashing in iPad Only and not getting help from logs Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Subtype: KERN_PROTECTION_FAILURE at 0x000000016d667fd0 Exception Codes: 0x0000000000000002, 0x000000016d667fd0 VM Region Info: 0x16d667fd0 is in 0x16d664000-0x16d668000; bytes after start: 16336 bytes before end: 47 REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL MALLOC_SMALL 132c00000-133000000 [ 4096K] rw-/rwx SM=PRV GAP OF 0x3a664000 BYTES ---> STACK GUARD 16d664000-16d668000 [ 16K] ---/rwx SM=NUL stack guard for thread 0 Stack 16d668000-16d764000 [ 1008K] rw-/rwx SM=SHM thread 0 Termination Reason: SIGNAL 11 Segmentation fault: 11 Terminating Process: exc handler [10927] Triggered by Thread: 0 Thread 0 name: Dispatch queue: com.apple.main-thread Thread 0 Crashed: 0 UIKitCore 0x186fae04c __66-[UITraitCollection _traitCollectionByModifyingTraitsCopyOnWrite:]_block_invoke_2 + 4 1 UIKitCore 0x186faefdc __54-[UITraitCollection traitCollectionByModifyingTraits:]_block_invoke + 36 2 UIKitCore 0x186fabfc8 -[UITraitCollection _traitCollectionByModifyingTraitsCopyOnWrite:] + 252 3 UIKitCore 0x187109b08 -[UITraitCollection traitCollectionByModifyingTraits:] + 120 4 UIKitCore 0x1871c013c -[UIScreen _defaultTraitCollectionForInterfaceOrientation:inBounds:] + 224 5 UIKitCore 0x1871bff8c -[UIApplication _isOrientationVerticallyCompact:] + 48 6 UIKitCore 0x1871bcd28 -[UIApplication _isStatusBarHiddenForOrientation:] + 24 7 UIKitCore 0x186fe0d10 +[UIWindow(StatusBarManager) _prefersStatusBarHiddenInWindow:targetOrientation:animationProvider:] + 260 8 UIKitCore 0x186fe310c +[UIWindow(StatusBarManager) _prefersStatusBarHiddenInWindow:animationProvider:] + 72 9 UIKitCore 0x186fe2e00 -[UIApplication _isStatusBarEffectivelyHiddenForContentOverlayInsetsForWindow:] + 132 10 UIKitCore 0x186fe0a9c -[UIWindow _sceneSafeAreaInsetsIncludingStatusBar:] + 184 11 UIKitCore 0x187037628 -[UIWindow _normalizedSafeAreaInsets] + 64 12 UIKitCore 0x1870375a0 -[UIWindow safeAreaInsets] + 76 13 UIKitCore 0x186fa6c70 -[UIView _updateSafeAreaInsets] + 68 14 UIKitCore 0x188529824 -[UIView _recursiveEagerlyUpdateSafeAreaInsetsUntilViewController] + 176
Topic: UI Frameworks SubTopic: UIKit Tags:
1
0
415
Mar ’25