I was looking through: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ScriptableCocoaApplications/SApps_handle_AEs/SAppsHandleAEs.html And wondered how these are handled for SwiftUI apps. What would I add or override?
Search results for
swiftui
16,581 results found
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Code example: // // ListSafeAreaBarKeyboardTextField.swift // Exploration import SwiftUI import Foundation struct ListSafeAreaBarKeyboardTextField: View { @State private var typedText: String = @FocusState private var focusingTextField: Bool private let items = Array(1...16) var body: some View { ScrollViewReader { proxy in List(items, id: .self) { number in Text(Item (number)) .id(number) } .onAppear { if let lastItem = items.last { proxy.scrollTo(lastItem, anchor: .bottom) } } .onChange(of: focusingTextField) { oldValue, newValue in // This simply won't work // ~ 12th - 16th item will still get covered by keyboard if newValue == true { // Delay to allow keyboard animation to complete DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { if let lastItem = items.last { withAnimation { proxy.scrollTo(lastItem, anchor: .top) } } } } } } .scrollDismissesKeyboard(.interactively) .safeAreaBar(edge: .bottom) { TextField(Type here, text: $typedText, axis: .vertical) .focused($focusingTextField) // Design
More example here: // // ListSafeAreaBarKeyboardTextField.swift // Exploration import SwiftUI import Foundation struct ListSafeAreaBarKeyboardTextField: View { @State private var typedText: String = @FocusState private var focusingTextField: Bool private let items = Array(1...16) var body: some View { ScrollViewReader { proxy in List { ForEach(items, id: .self) { number in Text(Item (number)) .id(number) } Text(Scroll to This) .id(ScrollToThis) } .defaultScrollAnchor(.bottom) .onAppear { if let lastItem = items.last { proxy.scrollTo(lastItem, anchor: .bottom) } } .onChange(of: focusingTextField) { oldValue, newValue in // if TextField is focused if newValue == true { // We scroll to the known last item (ScrollToThis) // ❌ (Somehow) This simply never works withAnimation { proxy.scrollTo(ScrollToThis, anchor: .bottom) } } } } .scrollDismissesKeyboard(.interactively) .safeAreaBar(edge: .bottom) { TextField(Type here, text: $typedText, axis: .vertical) .focused($focusingTextField) // Design .padding(.ho
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
SwiftUI's colorScheme modifier is said to be deprecated in favour of preferredColorScheme but the two work differently. See the below sample app, colorScheme changes the underlying view colour while preferredColorScheme doesn't. Is that a bug of preferredColorScheme? import SwiftUI struct ContentView: View { let color = Color(light: .red, dark: .green) var body: some View { VStack { HStack { color.colorScheme(.light) color.colorScheme(.dark) } HStack { color.preferredColorScheme(.light) color.preferredColorScheme(.dark) } } } } #Preview { ContentView() } @main struct TheApp: App { var body: some Scene { WindowGroup { ContentView() } } } extension UIColor { convenience init(light: UIColor, dark: UIColor) { self.init { v in switch v.userInterfaceStyle { case .light: light case .dark: dark case .unspecified: fatalError() @unknown default: fatalError() } } } } extension Color { init(light: Color, dark: Color) { self.init(UIColor(light: UIColor(light), dark: UIColor(dark))) } }
using Version 26.2 (17C52) I often get Trace file had no SwiftUI data why so?
Steps: In Xcode, choose Product → Profile Use the standard SwiftUI App template Keep the template settings at their defaults Start a profiling session If I stop the session while the app is still on the home screen, everything usually completes normally Start another profiling session and interact with the app a bit more Observed behavior: Occasionally, after running a longer session, I see a message related to ktrace Even after this appears, I can still sometimes run another short profiling session successfully In other cases, I see a different message indicating that data could not be collected I have also seen a message indicating that no SwiftUI data was available (I don’t currently have a screenshot for this case)
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
I am trying to port my sandboxed macOS app completely over to iOS using a Catalyst target. In my macOS app, I use 'SwiftySandboxFileAccess' package to add a symlink to '~/Library/PDF Services' so that the 'share to my app' menuItem shows up in the macOS Print Panel (in the PDF menu). It is critical for the function of my app to have this work on macOS. In the Catalyst target, I am having problems gaining access to '~/Library'. I have tried having the user select the folder, but the picker always returns 'canceled'. I have a test app that illustrates this. The test app tries to coax the user into selecting the library folder and then it is supposed to bookmark the location, but I am unable to get this far. As an aside, macOS should probably automatically add an entry to the Print Panel when the app includes PDF as a document type in XCode; it would save a lot of hassle and avoid having to go outside of the sandbox. However, I cannot wait for that. Hopefully someone can help. Download Test App from iCloud (If y
Topic:
App & System Services
SubTopic:
General
It will hurt some Texas users, but not the rest of the world, which is very important. I agree – one of my main concerns is how these laws will impact on all my other users. Should we terminate the app ? You could do that, but it's not a very good user experience. I plan to present some simple messaging that directs users to an Apple support article. Here's a quick sketch of how I'm currently planning to handle this across a few different apps (in SwiftUI). I would appreciate any feedback on this approach, from either a technical or legal standpoint. In my main App struct, I will branch into a new ContentViewWithAgeGate view for iOS 26.2+. WindowGroup { if #available(iOS 26.2, *) { ContentViewWithAgeGate() } else { ContentView() } } ContentViewWithAgeGate acts as a wrapper around ContentView and perfoms the checks: import SwiftUI @preconcurrency import DeclaredAgeRange @available(iOS 26.2, *) struct ContentViewWithAgeGate: View { @Environment(.requestAgeRange) var requestAgeRange @State priv
Topic:
App Store Distribution & Marketing
SubTopic:
General
Tags:
When using App Intent, I noticed that we cannot process the image directly within the invoked UI. It appears that this is restricted by Apple’s privacy protections—any attempt to handle the data immediately results in the background privacy indicator showing a blocked status. Therefore, App Intent does not seem to meet our need to process user-provided images directly. This sounds like you implemented a UI snippet as part of your intent, and not all SwiftUI features are available in a UI snippet — for example, these snippets aren't interactive. Details here matter, so to discuss how you can build an intent that works for your needs, it'd be helpful to have a test project or test code that demonstrates what you tried and where you ran into trouble so that we can more fully explore this. — Ed Ford, DTS Engineer
Topic:
App & System Services
SubTopic:
Automation & Scripting
Tags:
Thank you for your post. Very interesting to me because my recent instrument adventures. Although I am not an expert in Instruments, I recently discovered that you can create a blank template and add individual instruments like SwiftUI by tapping the plus icon. Is that what you are using for your SwiftUI data, and you are not receiving it that way? What template are you using that indicates there is no SwiftUI data on the trace? Could you please provide me with a detailed step-by-step guide to reproduce the issue, including the template and individual instruments you are adding to the instruments? Additionally, please provide any relevant background information about the application you are profiling. Thanks, Albert Pascual
Worldwide Developer Relations.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
(0) check if iOS is 26+. Otherwise, proceed without any test (because we cannot do them) Yep, agree. In fact, we specifically need to check for iOS 26.2. in (1), which import to use AppStore.ageRatingCode ? You just need to import storekit to access that. However, as noted below, I'm considering a different option. in (2), if UIKit and not SwiftUI, need the in parameter Indeed you do. Annoyingly, you also need the in parameter if you're putting your code in some class (e.g. some kind of age manager class), and it's not clear to me what you need to pass in (assuming you have a SwiftUI app). where should parental control be tested ? In step (5) ? I honestly don't know at this point – I haven't gotten to that point yet, but as noted below, I'm looking for ways to avoid that side of things. where to deal with change in user's age or repudiation (as required by law if I read properly) My assumption is that if you check the age on every launch, then this should take care of itself. But I could be
Topic:
App Store Distribution & Marketing
SubTopic:
General
Tags:
I have found that following code runs without issue from Xcode, either in Debug or Release mode, yet crashes when running from the binary produced by archiving - i.e. what will be sent to the app store. import SwiftUI import AVKit @main struct tcApp: App { var body: some Scene { WindowGroup { VideoPlayer(player: nil) } } } This is the most stripped down code that shows the issue. One can try and point the VideoPlayer at a file and the same issue will occur. I've attached the crash log: Crash log Please note that this was seen with Xcode 26.2 and MacOS 26.2.
@jwcarr thanks for this detailed analysis. That's the type of advice we would have expected from Apple… I think they have ways to avoid the legal issues. A few more points: There should likely be a step (0) (0) check if iOS is 26+. Otherwise, proceed without any test (because we cannot do them) (1) get the App Store age rating with let appStoreAgeRating = await AppStore.ageRatingCode ?? 18, (2) request the user's age with let ageRangeResponse = try await AgeRangeService.shared.requestAgeRange(ageGates: appStoreAgeRating), (3) check that the user has agreed to share their age, (4) check that lowerBound >= appStoreAgeRating, and (5) check that the verification method is not one of the self-declared methods. If this procedure fails, I should block access to the app and provide a link to Apple's support page A few more questions: in (1), which import to use AppStore.ageRatingCode ? in (2), if UIKit and not SwiftUI, need the in parameter let ageRangeResponse = try await AgeRangeService.shared.requestAg
Topic:
App Store Distribution & Marketing
SubTopic:
General
Tags:
Thanks so much for the post and the video itself. Would you be able to provide a focused sample project so I can run it myself and see if you are using UIKit or SwiftUI and what is causing the issue? If so, please share a link to your test project. That'll help us better understand what's going on. If you're not familiar with preparing a test project, take a look at Creating a test project. Thanks Albert Pascual
Worldwide Developer Relations.
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags:
I am creating a macOs SwiftUI document based app, and I am struggling with the Window sizes and placements. Right now by default, a normal window has the minimize and full screen options which makes the whole window into full screen mode. However, I don't want to do this for my app. I want to only allow to fill the available width and height, i.e. exclude the status bar and doc when the user press the fill window mode, and also restrict to resize the window beyond a certain point ( which ideally to me is 1200 x 700 because I am developing on macbook air 13.3-inch in which it looks ideal, but resizing it below that makes the entire content inside messed up ). I want something like this below instead of the default full screen green When the user presses the button, it should position centered with perfect aspect ratio from my content ( or the one I want like 1200 x 700 ) and can be able to click again to fill the available width and height excluding the status bar and docs. Here is my entire @main cod