Such a simple piece of code: import SwiftUI import WebKit struct ContentView: View { var body: some View { WebView(url: URL(string: https://www.apple.com)) } } When I run this, the web content shows under the top notch’s safe area, and buttons inside that region aren’t tappable. I tried a bunch of things and the only “fix” that seems to work is .padding(.top, 1), but that leaves a noticeable white strip in non-portrait orientations. What’s the proper way to solve this? Safari handles the safe area correctly and doesn’t render content there.
Search results for
swiftui
16,584 results found
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
in swiftui how can I change the text color when use menu? I mean I need that each text in pippo will be .red color as you can see in the code, but .foregroundColor(.red) do not works thanks var pippo = [AAA,BBB,CCC, DDD] var body: some View { Menu { ForEach(pippo, id: .self) { item in Button { //categoriaSelezionata = categoria } label: { Text(item) .foregroundColor(.red) } } } label: { HStack { Text(Select Theme) .multilineTextAlignment(.center) Image(systemName: chevron.down) .foregroundColor(.gray) } .frame(maxWidth: .infinity) .padding(6) } Menu { ForEach(pippo, id: .self) { item in Button(item) { // azione } .foregroundColor(.red) } } label: { HStack { Text(Select Theme) Image(systemName: chevron.down) .foregroundColor(.gray) } .frame(maxWidth: .infinity) .padding(6) } .menuStyle(BorderlessButtonMenuStyle()) // Prova diversi stili .menuIndicator(.hidden) // Nasconde l'indicatore di default }
Topic:
UI Frameworks
SubTopic:
SwiftUI
What most likely has happened is Apple made changes to the user interface in Xcode 26 and the tutorial you are following has not been updated for Xcode 26. You can file a request for Apple to update the tutorial. In Xcode choose Help > Provide Feedback to send the request. I have not gone through the tutorial so I can't tell you how to go through the tutorial in Xcode 26. I recommend taking the 100 Days of SwiftUI at Hacking with Swift. https://www.hackingwithswift.com/100/swiftui This course is geared towards beginners. Hacking with Swift also has a dedicated forum for the course (https://www.hackingwithswift.com/forums/100-days-of-swiftui) to ask questions when you run into problems with the course. The forums at Hacking with Swift are more beginner-friendly than Apple's forums.
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags:
In the Swift UI tutorial on the official website of apple developers, https://developer.apple.com/tutorials/swiftui/creating-and-combining-views, Step 2 in Section 2, through Command-Control-click, the full menu in Figure 1 cannot appear, but the style of Figure 2 appears, and the Show SwiftUI Inspector option is missing, see Figure 2. Similarly, in Step 6 of Section 2, Control-clicking on the Text declaration in the code editor, the options in the red box in Figure 3 cannot appear, and It is the style of Figure 4, and all the options in the red box of Figure 3 are missing. There is no one in Show Coding Tooks. I am using Macbook air 2020 M1, macOS is the latest Tahoe 26.1, and the xcode version is 26.1. The project files used in the learning tutorial are downloaded directly from the above link. Thank you very much for your help to a beginner, which is very urgent for me. I look forward to your reply and sincerely thank you again.
I have two @Observable manager classes, which share a reference to a third class. I initialize this setup using a custom init in my App struct, like so: @main struct MyApp: App { private let managerA: ManagerA private let managerB: ManagerB init() { let managerC = ManagerC() self.managerA = ManagerA(managerC: managerC) self.managerB = ManagerB(managerC: managerC) } var body: some Scene { WindowGroup { ContentView() .environment(managerA) .environment(managerB) } } } I've been using this pattern for some time and it has been working fine. However, I just today discovered that @Observable objects are supposed to be initialized as @State vars, as shown in Apple's documentation here. This means I shoud be doing the following: @main struct MyApp: App { @State private var managerA: ManagerA @State private var managerB: ManagerB init() { let managerC = ManagerC() self.managerA = ManagerA(managerC: managerC) self.managerB = ManagerB(managerC: managerC) } var body: some Scene { WindowGroup { ContentView() .environment
I'm working on an iOS document-based app. It uses ReferenceFileDocument and custom creation of documents via DocumentGroupLaunchScene + NewDocumentButton. It works fine when I use the plain NewDocumentButton(Whatever) (without any more arguments), but when I want to perform additional setup via preapreDocumentURL or even just add a contentType it gives such output in the console when I hit it: Content serialization failed, document won't be saved. UTType.replayable is correctly wired up in the plist. It looks like a bug in the SDK, but maybe there is a chance that I'm doing something wrong? Here's a code: import SwiftUI import UniformTypeIdentifiers import Combine @main struct MyApp: App { var body: some Scene { DocumentGroup { Document() } editor: { documentConfiguration in EmptyView() } DocumentGroupLaunchScene(Yoyo) { NewDocumentButton(contentType: .replayable) { return URL(string: whatever, it doesnt even go there...)! } } } } final class Document: ReferenceFileDocument { static var readableConte
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
Files and Storage
File Provider
SwiftUI
Uniform Type Identifiers
If you’re performing any significant work on your state’s default value or instantiating Observable objects, we recommend handling that differently for optimal performance. For example: struct MyView: View { @State private var object = MyObject() var body: some View { ContentView(object) } } That's not the best for performance, because MyObject will be instantiated eagerly every time MyView is initialized, which is expensive since it allocates a new object, Instead defer the creation of the object using callbacks like, ,task, .onAppear or .onChange(of:). For example: struct MyView: View { @State private var object: MyObject? var body: some View { ContentView(object) .task { object = MyObject() } } } If the model needs to be part and owned by the view, then use @State. If the model needs to be global to your appliction use @Environment. Please review WWDC23 Session: Discover Observation in SwiftUI and Managing model data in your app
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
Hello all, my team and I are looking for some advice on updating our app from using NavigationView and NavigationLink to NavigationStack and .navigationDestination now that NavigationView is deprecated. A little background about our situation, our app is a mix of SwiftUI views and UIKit view controllers. We are slowly migrating towards primarily SwiftUI and we are at the point now where our main app entry point is SwiftUI. UIKit is now mainly just used for some legacy screens inside the app, but majority of our navigation is using SwiftUI with NavigationLinks. I have spent a couple weeks on trying to migrate to using NavigationStack + .navigationDestination, but every time I do I keep running into issues. From what I understand, there seems to be two competing approaches for modern navigation. Those two approaches are... Having a more global navigationDestination modifier defined at the root of each tab that essentially supports navigating to all pages. I have seen this ref
Topic:
UI Frameworks
SubTopic:
SwiftUI
Hi there! I'm making an app that stores data for the user's profile in SwiftData. I was originally going to use UserDefaults but I thought SwiftData could save Images natively but this is not true so I really could switch back to UserDefaults and save images as Data but I'd like to try to get this to work first. So essentially I have textfields and I save the values of them through a class allProfileData. Here's the code for that: import SwiftData import SwiftUI @Model class allProfileData { var profileImageData: Data? var email: String var bio: String var username: String var profileImage: Image { if let data = profileImageData, let uiImage = UIImage(data: data) { return Image(uiImage: uiImage) } else { return Image(DefaultProfile) } } init(email:String, profileImageData: Data?, bio: String, username:String) { self.profileImageData = profileImageData self.email = email self.bio = bio self.username = username } } To save this I create a new class (I think, I'm new) and save it through ModelContext im
I'm having a real tough time replicating the error in some brand new packages (even though they seem essentially the same) but I have been able to isolate the issue in my two custom packages to where I can sort of see when the error exists. I have a package A that has a dependency on package B (which has two products). If I include a single Swift file in both packages with no source code it works but if I just add a single import SwiftUI statement to both package A and package B's singular file the error presents itself. I see the following note also attached in the build error: note: Swift Overlay dependency of 'SwiftUI' on 'UIKit' via Clang module dependency: 'SwiftUI.swiftmodule -> SwiftUI.pcm -> UIKit.pcm' (in target '' from project '')
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags:
Hi @VaiStardom I can confirm SpatialTapGesture doesn't consistently register direct input (trigger callbacks) on entities outside a person's field of view. However, you can use hand tracking to create a custom gesture that works on all entities, regardless of their position, as long as visionOS can track the person's hands. This approach only works within an ImmersiveSpace and requires adding an NSHandsTrackingUsageDescription entry to your app's Info.plist that explains why your app needs hand tracking access. The code snippet below demonstrates this technique by playing a sound when a person taps a cube, even when it's outside their field of view. import RealityKit import SwiftUI import AudioToolbox struct ImmersiveView: View { @State var spatialTrackingSession = SpatialTrackingSession() @State var collisionEventSubscription: EventSubscription? var body: some View { RealityView { content in let cube = ModelEntity( mesh: .generateBox(size: 0.1), materials: [SimpleMaterial(color: .green, isMetallic:
Topic:
Spatial Computing
SubTopic:
ARKit
Tags:
A good staring point would be to review the following resources: Understanding the navigation stack Migrating to new navigation types WWDC22 session 10054: The SwiftUI cookbook for navigation. Without being prescriptive, your app’s navigation structure would depend on your app’s structure and the various functionalities it supports, such as state restoration, deep linking etc.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Sorry got confused with all the code. import SwiftUI import SwiftData @main struct fbla_appApp: App { var body: some Scene { WindowGroup { ContentView() } .modelContainer(for: allProfileData.self) } }
Topic:
UI Frameworks
SubTopic:
General
Tags:
My main app target builds fine and can run on Simulator without issue. Whenever I try to run a Preview, I get this error: == DATE: Monday, November 3, 2025 at 2:52:23 PM Pacific Standard Time 2025-11-03T22:52:23Z == PREVIEW UPDATE ERROR: SimulatorShutdownUnexpectedlyError: Simulator was shutdown during an update Simulator [F85A5AF1-F52C-4662-AFCD-762F87AF537D] failed to boot and may have crashed. This seems like it started happening after updating to MacOS 26. I've tried reinstalling all Simulators, tried on Xcode 26, deleted derived data, restarted Xcode and my Mac several times. What other troubleshooting steps can I take?
I have a working XIB App to run a Linux VM with graphics interface. I am trying to rewrite it in SwiftUI but fall into all sorts of problems when using a combination of a Representable of the VZVirtualMachineView, an associated Coordinator, and @StateObjects. a) The VM display is not updated when running but is displayed if I close the window and reopen it. As the underlying VZVirtualMachineView is created/dismantled many times, there are warnings about negative scanouts that end up crashing the App b) Keyboard focus is not really working. https://developer.apple.com/forums/thread/766014 reports that there is probably a solution making a NSViewControllerReporesentable rather than a VZVirtualMachineViewRepresentable. I think I am fighting against proper SwiftUI lifecycle and would love to have a hint at what shall be the right organization of model and SwiftUI constructs.