I have an app currently in beta testing, and my primary QA person tries to send the crash log for this one particular bug:
The night before, he finished testing the app on an iPhone, left the app running in the background and the phone charging. The phone went to sleep. The phone is running the latest release of iOS 18.
In the morning he wakes up the phone and gets the alert that the app "xxx Crashed. Do you want to share additional information with the developer?" He taps Share, but I don't get a crash log in the organizer.
I've gotten other crash logs in the organizer as recently as 2 weeks ago, This one has occurred several times and always fails to produce a report. I have tried doing the same steps without seeing any crash.
Any ideas?
Mike
SwiftUI
RSS for tagProvide views, controls, and layout structures for declaring your app's user interface using SwiftUI.
Posts under SwiftUI tag
200 Posts
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hello, I can't seem to set any breakpoint in didSet for all properties inside Observable.
Is this a bug?
XcodeVersion 15.2
(15C500b)
Thanks!
I’ve developed an Apple Watch extension for an existing iOS app. When I run the app on the watch via Xcode using the simulator, everything works fine. However, when I try to install it on my iPhone, the Watch app doesn’t show it in the "Available Apps" list, so I can't install it on the watch.
The Apple Watch is connected to my iPhone, and I can see other apps available for installation without any issues.
I also created a brand new project with watchOS support to troubleshoot, but the same problem occurred.
Any ideas on how to resolve this?
Hello.
I have successfully created a scrollview with several buttons that stack on top of one another. But the View won't scroll. What am i doing wrong here?
scrollView = UIScrollView.init(frame: CGRect.zero)
				scrollView.translatesAutoresizingMaskIntoConstraints = false
				
				
				self.view.addSubview(scrollView)
				var leadingAnchor = self.scrollView!.topAnchor
				for i in 0..<20{
						let t_button = UIButton.init(frame: CGRect.zero)
						t_button.translatesAutoresizingMaskIntoConstraints = false
						t_button.backgroundColor = UIColor.blue
						scrollView.addSubview(t_button)
						NSLayoutConstraint.activate([
								t_button.topAnchor.constraint(equalTo: leadingAnchor, constant:5.0),
								t_button.centerXAnchor.constraint(equalTo: scrollView.centerXAnchor),
								t_button.heightAnchor.constraint(equalToConstant: 50.0),
								t_button.widthAnchor.constraint(equalToConstant: 75.0)
						])
						
						leadingAnchor = t_button.bottomAnchor
						
						t_button.setTitle("Button \(i)", for: .normal)
						t_button.addTarget(self, action: #selector(scrollViewButtonAction(_:)), for: .touchUpInside)
						
				}
				
				NSLayoutConstraint.activate([
						scrollView.topAnchor.constraint(equalTo: self.titleHeader.bottomAnchor, constant: 10.0),
						scrollView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
						scrollView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor),
						scrollView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor),
				])
Hi, I'm working on visionOS and find I can't get onDisappear event just on the first window after app launch. It comes like that:
WindowGroup(id:"WindowA"){
MyView()
.onDisappear(){
print("WindowA disappear")
}
}
WindowGroup(id:"WindowB"){
MyView()
.onDisappear(){
print("WindowB disappear")
}
}
WindowGroup(id:"WindowC"){
MyView()
.onDisappear(){
print("WindowC disappear")
}
}
When the app first launch, it will open WindowA automatically
And then I open WindowB and WindowC programatically.
Then I tap the close button on window bar below window.
If I close WindowB/WindowC, I can receive onDisappear event
If I close WindowA, I can't receive onDisappear event
If I reopen WindowA after it is closed and then close it again by tap the close button below window, I can receive onDisappear event
Is there any logic difference for the first window on app launch? How can I get onDisappear Event for it.
I'm using Xcode 16 beta 2
I'm trying to do something so seemingly basic, yet I can't get it to work and I'm flummoxed.
In a basic, vanilla SwiftUI app for tvOS, embed a single Text element with a very long string (hundreds of lines) in it:
struct ContentView: View {
var body: some View {
ScrollView(.vertical) {
Text(veryLargeString)
.focusable()
}
}
}
Then fire up the app on tvOS, and it will not scroll. No matter what I do. Pressing arrow keys, swiping fast with my thumb, and nothing. It will not move. Ironically, in the Xcode SwiftUI Preview window—it does scroll, so that's always a fun tease.
What I do know is that the focus engine is throwing a few errors, so it's leading me to believe the issue is with how I have the focusable element attached. I'm using a combination of -UIFocusLoggingEnabled YES as well as listening for UIFocusSystem.movementDidFailNotification.
Unfortunately since this is SwiftUI, the notification failure and debugging logs aren't really all that actionable. Help appreciated!
To add a background to the tab content I implement the following background, nesting another modifier equal within this one.
.background(
.background // ERROR: Ambiguous use of 'background'
.shadow(.drop(
color: .primary.opacity(0.08),
radius: 5, x: 5, y: 5)
)
.shadow(.drop(
color: .primary.opacity(0.08),
radius: 5, x: -5, y: -5)
),
in: .capsule
)
TLDR: Applying a clipShape in a hoverEffect closure is preventing taps from getting through to buttons nested within an ornament.
I need to make a custom ornament menu, similar to the stock ornament available via TabView but with some visual tweaks. It displays icons, and then expands to display a label as the user hovers. Example:
I've put together a piece of sample code, following guidance from WWDC docs:
VStack {
}
.ornament(attachmentAnchor: .scene(.leading)) {
VStack {
ForEach(0...7, id:\.self) { index in
Button(action: {
print(index) // <---- This will not print
}) {
HStack {
Text("\(index)")
Text(" button")
}
}
}
}
.padding(12)
.glassBackgroundEffect()
.hoverEffect { effect, isActive, proxy in
effect
.clipShape(RoundedRectangle(cornerRadius: 36)
.size(width: isActive ? proxy.size.width : 72, height: proxy.size.height, anchor: .leading)
)
}
}
}
The buttons in this code cannot be interacted with, as the print statement never executes. What am I missing here? I've managed to get some weird behavior, sometimes a specific clipShape (like a circle) will allow a tap on a single button, but not others.
I am trying to discover how to display my application’s calculated Solar Information values in a chart.
My application identifies a selected location in MapKit.
The application identifies the location’s longitude, latitude, and current time of day.
The application calculates the selected location’s NOAA [SOLAR ELEVATION], and the [SOLAR AZIMUTH] for the time of day.
The application calculates the data, then stores the calculated values as a [Plist] file within my application’s Document Directory.
For the moment, complete with repeated scouring of the Internet, I am not sure how to properly convert, transfer, or create a Structure, required by the chart to display the calculated values. I would like to create the chart once the calculations are complete, but I introduced a Plist to store the calculations for future use, too.
The calculated values coincide with the NOAA Solar Calculations, complete to the displayed [h : m : s], whereas I also designed the application to create the [Array of Dictionary Objects] to store the calculated values for each subsequent six minute interval, until the end of the selected location’s day. The calculated values are properly appended to the [Array of Dictionary Objects] after each completed calculation, with data transfer constants. There are 240 calculations per day from [00:06:00 to 23:54:00], presented as a [STRING], complete with the [Elevation] presented as a [DOUBLE].
For example :: The application generates the following [Calculated Array of Dictionary Objects], then recreates, and appends a new Plist in the Document Directory.
mySolarElevationDataArrayOfDictionaries :: [(theRequiredTimeOfDay: "00:06:00", theCalculatedElevation: -62.60301082991259), (theRequiredTimeOfDay: "00:12:00", theCalculatedElevation: -62.94818095051292), (theRequiredTimeOfDay: "00:18:00", theCalculatedElevation: -63.245198186807215), (theRequiredTimeOfDay: "00:24:00", theCalculatedElevation: -63.49236786176319), (theRequiredTimeOfDay: "00:30:00", theCalculatedElevation: -63.688223890934175), (theRequiredTimeOfDay: "00:36:00", theCalculatedElevation: -63.831564163806945), (theRequiredTimeOfDay: "00:42:00", theCalculatedElevation: -63.921486675739004), (theRequiredTimeOfDay: "00:48:00", theCalculatedElevation: -63.95741610687708), to the end of the data :: ===> (theRequiredTimeOfDay: "23:54:00", theCalculatedElevation: -60.69355458181633)]
The application presents the initial data as follows ::
Then presents a compass view to illustrate the results ::
I modified the Chart’s [MOCK DATA] from the calculated values to test the Chart’s display in a [SwiftUI Hosting Controller].
For example :: The following Chart Mock Data in a [HourlySunElevation_MockChartData.swift] file is called by the application’s [Content View].
import Foundation
struct Value {
let theRequiredTimeOfDay: String
let theCalculatedElevation: Double
static func theSunElevationMockData() -> [Value] {
return [Value(theRequiredTimeOfDay: "00:06:00", theCalculatedElevation: -62.60301082991259), Value(theRequiredTimeOfDay: "00:12:00", theCalculatedElevation: -62.94818095051292), Value(theRequiredTimeOfDay: "00:18:00", theCalculatedElevation: -63.245198186807215), Value(theRequiredTimeOfDay: "00:24:00", theCalculatedElevation: -63.49236786176319), Value(theRequiredTimeOfDay: "00:30:00", theCalculatedElevation: -63.688223890934175), Value(theRequiredTimeOfDay: "00:36:00", theCalculatedElevation: -63.831564163806945), Value(theRequiredTimeOfDay: "00:42:00", theCalculatedElevation: -63.921486675739004), Value(theRequiredTimeOfDay: "00:48:00", theCalculatedElevation: -63.95741610687708), to the end of the data :: ===> Value(theRequiredTimeOfDay: "23:54:00", theCalculatedElevation: -60.69355458181633)]
The Chart illustrates the Mock Data as follows ::
I also created a Struct within the [MySunElevationChart_ViewController] to try to append the calculated data, using the same logic with the Plist data transfer constants, as employed by the [Array of Dictionary Objects] ::
struct ChartSolarElevationValues {
var theRequiredTimeOfDay: String
var theCalculatedElevation: Double
// Structs have an implicit [init]. This is here for reference.
init(theRequiredTimeOfDay: String, theCalculatedElevation: Double) {
self.theRequiredTimeOfDay = theRequiredTimeOfDay
self.theCalculatedElevation = theCalculatedElevation
//mySolarElevationChartData.append(self)
} // End of [init(theRequiredTimeOfDay: String, theCalculatedElevation: Double)]
} // End of [struct ChartSolarElevationValues]
Unfortunately, the result did not append each subsequent calculation, but continued to create the same calculation as a new distinct object ::
NOTE :: I only called three calculations with the Struct test.
// NOTE :: To prevent an [ERROR] at [var mySolarElevationChartData = [ChartSolarElevationValues]] since it has an init.
// Therefore you must add () at the end of [var mySolarElevationChartData = [ChartSolarElevationValues]]
let theData = [ChartSolarElevationValues]()
//print("theData :: \(theData)\n")
let someData = ChartSolarElevationValues(theRequiredTimeOfDay: TheTimeForDaySunElevation.theTheTimeForDaySunElevation, theCalculatedElevation:VerifyCityLocationSearchRequestCorrectedSolarElevation.theVerifyCityLocationSearchRequestCorrectedSolarElevation)
var theData_New = theData
theData_New.append(someData)
print("theData_New :: \(theData_New)\n")
// Prints :: theData_New :: [My_Map.ChartSolarElevationValues(theRequiredTimeOfDay: "00:06:00", theCalculatedElevation: -61.11000735370401)]]
// Prints :: [theData_New :: [My_Map.ChartSolarElevationValues(theRequiredTimeOfDay: "00:12:00", theCalculatedElevation: -61.315092082911875)]]
// Prints :: [theData_New :: [My_Map.ChartSolarElevationValues(theRequiredTimeOfDay: "00:18:00", theCalculatedElevation: -61.47403413313205)]]
So, I am misintepreting the required coding structure to properly append the Elevation Chart, and the Azimuth Chart with the calculated data.
I know something is amiss, but for the moment, I do not know how to address this issue.
Your suggestions would be welcome ... :]
jim_k
In order to setup a preview, I need to create a Book; to do that, I need to await a function – however, one cannot await inside a Preview:
import SwiftUI
struct BookView: View {
let book: Book
var body: some View {
VStack {
Image(book.thumbnail, scale: 1.0,
label: Text(book.title))
}
}
}
#Preview {
let url = URL(filePath: "/Users/dan/Documents/Curs confirmare RO.pdf")!
// 👇 here, `createBook` should be awaited; but how?
let book = createBook(for: url, of: CGSize(width: 254, height: 254), scale: 1.0)
BookView(book: book)
}
Hello team i notice that we have a problem in our app that every time the user opens a Textfield the app freezes when the keyboard appears, this behavior was tracked down and it's a UI breaking design on a UIView
[this view it's expandable and is original size is 80]
[when it gets expanded 206.33]
this is the view code I change the colors to easy check the other's views created inside
private lazy var sharedUIPlaybackView: UIView = {
let containerView = UIView().withAutoLayout()
let propertySearchCriteria = PropertySearchCriteriaBuilder(hotelSearchParameters: viewModel.hotelSearchParameters).criteria
var swiftUIView: SwiftUIView<LodgingPlaybackWrapper>! = nil
swiftUIView = SwiftUIView(
LodgingPlaybackWrapper(propertySearchCriteria: propertySearchCriteria,
playbackUpdateNotificationSender: playbackUpdateNotificationSender,
componentHandler: { [weak self] componentId in
self?.componentReady(componentId)
}),
viewDidLayoutSubviewsCallback: { [weak self] in
let extraPadding = self?.playbackViewExtraPadding ?? Spacing.spacing8x
let newHeight = swiftUIView.frame.size.height + extraPadding
// if newHeight != self?.sharedUIPlaybackViewHeightConstraint?.constant {
// self?.sharedUIPlaybackViewHeightConstraint?.constant = 206.33
// }else {
// self?.sharedUIPlaybackViewHeightConstraint?.constant = 80
// }
}
).withAutoLayout().withAccessibilityIdentifier("test")
// sharedUIPlaybackViewHeightConstraint = containerView.heightAnchor.constraint(equalToConstant: 0)
// sharedUIPlaybackViewHeightConstraint?.isActive = true
containerView.backgroundColor = .blue
swiftUIView.backgroundColor = .red
containerView.addSubview(swiftUIView)
containerView.addConstraints([
swiftUIView.topAnchor.constraint(equalTo: containerView.topAnchor, constant: playbackViewTopConstant),
swiftUIView.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: Spacing.spacing4x),
swiftUIView.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: -Spacing.spacing4x),
swiftUIView.bottomAnchor.constraint(equalTo: containerView.bottomAnchor, constant: -Spacing.spacing3x),
swiftUIView.heightAnchor.constraint(equalToConstant: 206.33)
])
return containerView
}()
old devs created this function viewDidLayoutSubviewsCallback to connect user interaction on the wrapper and used on UIKit.
this is the part where the math on the function gets weird and messed up the code by crashing the view
viewDidLayoutSubviewsCallback: { [weak self] in
let extraPadding = self?.playbackViewExtraPadding ?? Spacing.spacing8x
let newHeight = swiftUIView.frame.size.height + extraPadding
if newHeight != self?.sharedUIPlaybackViewHeightConstraint?.constant {
self?.sharedUIPlaybackViewHeightConstraint?.constant = newHeight
}
}
).withAutoLayout().withAccessibilityIdentifier("test")
sharedUIPlaybackViewHeightConstraint = containerView.heightAnchor.constraint(equalToConstant: 0)
sharedUIPlaybackViewHeightConstraint?.isActive = true
I commented this math because is crashing the app and instead of giving a dynamical height I placed as a constant constraint as default height this is how I solved the problem of the UI, but I still need to update the view each time the user clicks and gets call by the method viewDidLayoutSubviewsCallback
what can I do?
I tried to add like a conditional on the method
if newHeight == 80 {
containerView.addConstraints([
swiftUIView.heightAnchor.constraint(equalToConstant: 80.0)
])
containerView.layoutIfNeeded()
}
else {
containerView.addConstraints([
swiftUIView.heightAnchor.constraint(equalToConstant: 206.33)
])
containerView.layoutIfNeeded()
}
like this but it didn't work
[this is how it looks with the constant value of 206.33]
[when it gets open looks good]
When I show a window while a sky sphere is shown, the handles to drag/close/resize the window are hidden. The colliders still work, so they are there, but only the visuals are hidden. I already know from another project, that this also happens to volumes.
They only appear once you get closer to the window or if the sky sphere gets removed.
Is this a known issue or is there a fix for that?
.persistentSystemOverlays(.visible)does not fix it
Xcode 16.3.0 Beta, visionOS 2.4
This is the complete Playground code:
import MapKit
import SwiftUI
import PlaygroundSupport
struct AddressSearchView: View {
@State private var region = MKCoordinateRegion(
center: CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194),
span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01)
)
var body: some View {
VStack {
Map(position: .constant(MapCameraPosition.region(region))) {
}
.frame(height: 300)
}
}
}
struct AddressSearchView_Previews: PreviewProvider {
static var previews: some View {
AddressSearchView()
}
}
PlaygroundPage.current.setLiveView(AddressSearchView())
When I try to run this I get this in the debug console:
error: Couldn't look up symbols:
protocol witness table for _MapKit_SwiftUI.EmptyMapContent : _MapKit_SwiftUI.MapContent in _MapKit_SwiftUI
protocol witness table for _MapKit_SwiftUI.EmptyMapContent : _MapKit_SwiftUI.MapContent in _MapKit_SwiftUI
protocol witness table for _MapKit_SwiftUI.EmptyMapContent : _MapKit_SwiftUI.MapContent in _MapKit_SwiftUI
protocol witness table for _MapKit_SwiftUI.EmptyMapContent : _MapKit_SwiftUI.MapContent in _MapKit_SwiftUI
protocol witness table for _MapKit_SwiftUI.EmptyMapContent : _MapKit_SwiftUI.MapContent in _MapKit_SwiftUI
protocol witness table for _MapKit_SwiftUI.EmptyMapContent : _MapKit_SwiftUI.MapContent in _MapKit_SwiftUI
protocol witness table for _MapKit_SwiftUI.EmptyMapContent : _MapKit_SwiftUI.MapContent in _MapKit_SwiftUI
protocol witness table for _MapKit_SwiftUI.EmptyMapContent : _MapKit_SwiftUI.MapContent in _MapKit_SwiftUI
protocol witness table for _MapKit_SwiftUI.EmptyMapContent : _MapKit_SwiftUI.MapContent in _MapKit_SwiftUI
protocol witness table for _MapKit_SwiftUI.EmptyMapContent : _MapKit_SwiftUI.MapContent in _MapKit_SwiftUI
protocol witness table for _MapKit_SwiftUI.EmptyMapContent : _MapKit_SwiftUI.MapContent in _MapKit_SwiftUI
Hint: The expression tried to call a function that is not present in the target, perhaps because it was optimized out by the compiler.
the preview never shows up. If I use other SwiftUI components and not the map it works fine. What is happening?
Playground target is Swift 6 macOS (iOS does the same).
Xcode 16.2
Does causing a swiftui view refresh via modifying observed properties while an alert is visible allowed?
I am seeing a warning
'Presenting view controller <SwiftUI.PlatformAlertController> from detached view controller is not supported, and may result in incorrect safe area insets and a corrupt root presentation. Make sure <SwiftUI.PlatformAlertController> is in the view hierarchy before presenting from it. Will become a hard exception in a future release.'
and the warning
'Attempt to present <SwiftUI.PlatformAlertController> on (from ) while a presentation is in progress'.
The second warning occurs more often.
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)
I have an app that run Monte Carlo simulations. I run thousands of simulations in the app and a simulation runs can take on the order of 30 seconds to a minute to complete. I would like to have a progress view that tracks the number of simulation runs. How can I implement this in swiftui?
On macOS 15.4 beta 2 (24E5222f), the back button is not visible when navigating from a view with no toolbar to a view with a toolbar button. The back button is visible on macOS 15.3.1 and earlier versions.
Also, the toolbar button shown when run on macOS 15.4 beta 2 is truncated.
This is how it looks on macOS 15.4 beta 2:
And this is how it looks on macOS 15.3.1 and earlier:
Feedback ID: FB16743834
My app typically works with very large image files. Having it auto-save on every change is very expensive as most formats cannot be saved incrementally.
Is there a way to disable this and force the user to use the Save menu item on OSX, and possibly a Save button on iOS?
My UI is very heavyweight, so I'd like to show the previous versions using a lighter weight - almost like quick look - UI.
This would also allow me to 'zoom to fit' so the entire document can be seen.
I am using SwiftUI, but I wouldn't mind jumping into AppKit and/or UIKit to implement this.
I have implemented a SwiftUI view containing a grid of TextField elements, where focus moves automatically to the next field upon input. This behavior works well on iOS 16 and 17, maintaining proper focus highlighting when keyboard full access is enabled.
However, in iOS 18 and above, the keyboard full access focus behaves differently. It always stays behind the actual focus state, causing a mismatch between the visually highlighted field and the active text input. This leads to usability issues, especially for users navigating with an external keyboard.
Below is the SwiftUI code for reference:
struct AutoFocusGridTextFieldsView: View {
private let fieldCount: Int
private let columns: Int
@State private var textFields: [String]
@FocusState private var focusedField: Int?
init(fieldCount: Int = 17, columns: Int = 5) {
self.fieldCount = fieldCount
self.columns = columns
_textFields = State(initialValue: Array(repeating: "", count: fieldCount))
}
var body: some View {
let rows = (fieldCount / columns) + (fieldCount % columns == 0 ? 0 : 1)
VStack(spacing: 10) {
ForEach(0..<rows, id: \.self) { row in
HStack(spacing: 10) {
ForEach(0..<columns, id: \.self) { col in
let index = row * columns + col
if index < fieldCount {
TextField("", text: $textFields[index])
.frame(width: 40, height: 40)
.multilineTextAlignment(.center)
.textFieldStyle(RoundedBorderTextFieldStyle())
.focused($focusedField, equals: index)
.onChange(of: textFields[index]) { newValue in
if newValue.count > 1 {
textFields[index] = String(newValue.prefix(1))
}
if !textFields[index].isEmpty {
moveToNextField(from: index)
}
}
}
}
}
}
}
.padding()
.onAppear {
focusedField = 0
}
}
private func moveToNextField(from index: Int) {
if index + 1 < fieldCount {
focusedField = index + 1
}
}
}
struct AutoFocusGridTextFieldsView_Previews: PreviewProvider {
static var previews: some View {
AutoFocusGridTextFieldsView(fieldCount: 10, columns: 5)
}
}
Has anyone else encountered this issue with FocusState in iOS 18?
I really do believe that this is a bug strictly connected to keyboard navigation since I experienced similar problem also on UIKit equivalent of the view.
Any insights or suggestions would be greatly appreciated!