This topic area is about the programming languages themselves, not about any specific API or tool. If you have an API question, go to the top level and look for a subtopic for that API. If you have a question about Apple developer tools, start in the Developer Tools & Services topic.
For Swift questions:
If your question is about the SwiftUI framework, start in UI Frameworks > SwiftUI.
If your question is specific to the Swift Playground app, ask over in Developer Tools & Services > Swift Playground
If you’re interested in the Swift open source effort — that includes the evolution of the language, the open source tools and libraries, and Swift on non-Apple platforms — check out Swift Forums
If your question is about the Swift language, that’s on topic for Programming Languages > Swift, but you might have more luck asking it in Swift Forums > Using Swift.
General:
Forums topic: Programming Languages
Swift:
Forums subtopic: Programming Languages > Swift
Forums tags: Swift
Developer > Swift website
Swift Programming Language website
The Swift Programming Language documentation
Swift Forums website, and specifically Swift Forums > Using Swift
Swift Package Index website
Concurrency Resources, which covers Swift concurrency
How to think properly about binding memory Swift Forums thread
Other:
Forums subtopic: Programming Languages > Generic
Forums tags: Objective-C
Programming with Objective-C archived documentation
Objective-C Runtime documentation
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
Swift
RSS for tagSwift is a powerful and intuitive programming language for Apple platforms and beyond.
Posts under Swift tag
200 Posts
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hi Community!
I'm wrangling with this for a few days now and can't find a way to fix it, but I see it working in other apps.
I have a regular UIToolbar with buttons, assigning it as inputAccessoryView to a UITextView, so the toolbar appears above the keyboard (I can reproduce this also in SwiftUI).
The toolbar contains regular UIBarButtonItems, except one doesn't have an action, it has a UIMenu (using .menu = UIMenu...).
In the Apple Notes app, there is also one button that shows a menu like that. When you tap on the button, the toolbar disappears and the menu shows directly above the keyboard.
However, in my code it shows above the hidden toolbar, means there is a huge gap between keyboard and menu. It works if I attach the toolbar (in SwiftUI) to the navigation at the top or bottom, just with the keyboard it behaves differently.
Here is some sample code for the toolbar:
private lazy var accessoryToolbar: UIToolbar = {
let toolbar = UIToolbar()
let bold = UIBarButtonItem(image: UIImage(systemName: "bold"), style: .plain, target: self, action: #selector(didTapToolbarButton(_:)))
let italic = UIBarButtonItem(image: UIImage(systemName: "italic"), style: .plain, target: self, action: #selector(didTapToolbarButton(_:)))
let underline = UIBarButtonItem(image: UIImage(systemName: "underline"), style: .plain, target: self, action: #selector(didTapToolbarButton(_:)))
let todo = UIBarButtonItem(image: UIImage(systemName: "checklist"), style: .plain, target: self, action: #selector(didTapToolbarButton(_:)))
// Make the Bullet button open a menu of list options
let bullet = UIBarButtonItem(image: UIImage(systemName: "list.bullet"), style: .plain, target: self, action: nil)
let bulletMenu = UIMenu(title: "Insert List", children: [
UIAction(title: "Bulleted List", image: UIImage(systemName: "list.bullet")) { [weak self] _ in
self?.handleMenuSelection("Bulleted List")
},
UIAction(title: "Numbered List", image: UIImage(systemName: "list.number")) { [weak self] _ in
self?.handleMenuSelection("Numbered List")
},
])
bullet.menu = bulletMenu
toolbar.items = [bold, italic, underline, todo, bullet]
toolbar.sizeToFit()
return toolbar
}()
Somewhere else in the code assign it to the UITextView:
// Attach the toolbar above the keyboard
textView.inputAccessoryView = accessoryToolbar
Toolbar:
Menu open:
In Apple Notes:
I feel I miss something. In Apple notes I can also see a Liquid Glass style gradient between the toolbar and keyboard, dimming the content in this space.
Hi,
I've tried to find a solution for this problem for weeks now but it seems no one knows how to solve it and Apple doesn't seem to care.
I have a NavigationSplitView with two columns. In the detail column I have a button - or any other clickable control - which is placed in the very top where usually the safe area resides.
The button is NOT clickable when he is in the safe area and I have NO idea why. I know I can place buttons in safe areas of other views and they are clickable.
Please have a look at the code:
`struct NavTestView: View {
var body: some View {
GeometryReader { p in
VStack(spacing: 0) {
NavigationSplitView {
List(names) {
Text($0.name).frame(width: p.size.width)
.background(Color.green)
}.listRowSpacing(p.size.height * 0.15 / 100 )
.toolbar(.hidden, for: .navigationBar)
} detail: {
TestView().ignoresSafeArea()
}.frame(width: p.size.width, height: p.size.height, alignment: .topLeading)
.background(Color.yellow)
}
}
}
}
struct TestView: View {
var body: some View {
GeometryReader { p in
let plusButton = IconButton(imageName: "plus.circle.fill", color: Color(uiColor: ThemeColor.SeaFoam.color),
imageWidth: p.size.width * 5 / 100, buttonWidth: p.size.width * 5 / 100)
let regularAddButton = Button(action: { log.info("| Regular Add Button pressed") } ) {
plusButton
}
VStack {
regularAddButton
}.frame(width: p.size.width , height: p.size.height, alignment: .top)
.background(Color.yellow)
}
}
}
`
this code produces the following screen:
Any help would be really greatly appreciated!
Thank you!
Frank
Hi,
I have a NavigationSplitView with a view in the detail section:
NavigationSplitView {
ZStack {
Color.black.ignoresSafeArea()
gradientBlack2Blue.opacity(0.25)
.ignoresSafeArea()
GeometryReader { p in
VStack {
List {
SidebarViewCell(id: "1",
text: "Steuersätze" ,
type: .TAX_MASTERDATA ,
selectedMasterdataType: $selectedMasterdataType)
}.listRowSpacing(size.height * 1.25 / 100 )
.scrollContentBackground(.hidden)
.toolbar(.hidden, for: .navigationBar)
.frame(width: p.size.width * 98 / 100 , height: p.size.height,
alignment: .topLeading).
}alignment: .topLeading)
}
}
}
detail: {
MasterdataDetailView().ignoresSafeArea()
}
}.navigationSplitViewStyle(.balanced)
When I place a Button-Control in the MasterdataDetailView it cannot be clicked because it is in the safe area. How can I make it clickable?
Best Regards,
Frank
Hi all, I'm tuning my app prediction speed with Core ML model. I watched and tried the methods in video: Improve Core ML integration with async prediction and Optimize your Core ML usage. I also use instruments to look what's the bottleneck that my prediction speed cannot be faster.
Below is the instruments result with my app. its prediction duration is 10.29ms
And below is performance report shows the average speed of prediction is 5.55ms, that is about half time of my app prediction!
Below is part of my instruments records. I think the prediction should be considered quite frequent. Could it be faster?
How to be the same prediction speed as performance report? The prediction speed on macbook Pro M2 is nearly the same as macbook Air M1!
Hello Apple Developer Forum,
I got the following statement from the AI model. It seems it is also reflecting my real-world experience.
Where do I find an official source that fully describes the array on swiftData model behaviour?
When a SwiftData model contains
an array of value types, such as [String] or [Int],
the array's order is preserved
Xcode downloaded a crash report for my app that crashed when trying to insert a String into a Set<String>. Apparently there was an assertion failure ELEMENT_TYPE_OF_SET_VIOLATES_HASHABLE_REQUIREMENTS. I assume that this assertion failure happened because the hash of the new element didn't match the hash of an equal already inserted element, but regardless, I don't understand how inserting a simple string could trigger this assertion.
Here is essentially the code that leads to the crash. path is any file system directory, and basePath is a directory higher in the hierarchy, or path itself.
var scanErrorPaths = Set<String>()
func main() {
let path = "/path/to/directory"
let basePath = "/path"
let fileDescriptor = open(path, O_RDONLY)
if fileDescriptor < 0 {
if (try? URL(fileURLWithPath: path, isDirectory: false).checkResourceIsReachable()) == true {
scanErrorPaths.insert(path.relativePath(from: basePath)!)
return
}
}
extension String {
func relativePath(from basePath: String) -> String? {
if basePath == "" {
return self
}
guard let index = range(of: basePath, options: .anchored)?.upperBound else {
return nil
}
return if index == endIndex || basePath == "/" {
String(self[index...])
} else if let index = self[index...].range(of: "/", options: .anchored)?.upperBound {
String(self[index...])
} else {
nil
}
}
}
crash.crash
"/Users/rich/Work/IdeaBlitz/IdeaBlitz/IdeaListView.swift:30:25 The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions"
Is it just me? I get this on syntax errors, missing commas, missing quotes, and for no particular reason at all that I can see. I don't think I've been able to write a single, simple, SwiftUI view without seeing this multiple times.
"Breaking it up" just makes it harder to read. Simple, inline, 2-page views become 8-page, totally unreadable, monstrosities.
Am I doing something wrong? Or is this just the state of SwiftUI today? Or is there some way to tell the compiler to take more time on this expression? I mean, if these can be broken up automatically, then why doesn't the compiler to that already?
We are not receving incoming call from blocked numbers below iOS 26 versions but same in iOS 26 onwards we are receiving the incoming call..
Can you please provide any solutions to fix the issue
I am currently developing a macOS app that can show system HUDs in the Notch
Till Sequoia I used to kill the OSDUIHelper process (which displays the default macOS Volume and Brightness control HUDs) - and replaced it with my app's HUDs
But, it is not working on macOS Tahoe anymore as the OSDUIHelper process is no longer there due to the UI changes
Has the process been renamed - or is there any other way to kill the process?
I’m integrating the Declared Age Range feature to tailor our app’s experience based on a user’s age range. I’m currently in the testing phase and would like to repeatedly test the consent flow and different outcomes from AgeRangeService.shared.requestAgeRange(...).
However, once I go through the consent flow and choose to share, the age-range sharing sheet no longer appears on subsequent attempts—so it’s hard to validate edge cases (e.g., changed gates, declined flow, re-prompt behavior).
Could you advise on the recommended way to reset or re-prompt during development? In particular:
Is there a supported way to clear per-app consent so the system prompts again?
Under what conditions should the “Share Age Range Again” control appear in Settings, and is there an equivalent way to trigger it for testing?
Are there best practices for QA (e.g., using Ask First at the system level, testing on real devices vs. Simulator, using a separate bundle ID for dev builds, or other steps)?
Any other guidance for validating different requestAgeRange results (e.g., declined/not available) would be appreciated.
In SwiftUI I am using the manageSubscriptionsSheet modifier to open the iOS subscription screen. When this is presented it immediately flashes a white view and then animated the subscription screen up from the bottom, it looks pretty bad.
The view I am calling manageSubscriptionsSheet on is presented in a sheet, so maybe trying to present the subscriptions view as well is causing the visual glitch. Any way to not have this white flashing view when opening the subscription screen?
Hi,
is there a compiled version of MailCore.swift? I want to build an easy-to-use mail app for my mother, who is 97, has a MacBook Air, but Apple Mail is too complicated for her. chatGPT said I am too stupid to compile it by myself.
Regards Stephan
Hello!
Bare with me here, as there is a lot to explain!
I am working on implementing a Game Center high score leaderboard into my game. I have looked around for examples of how to properly implement this code, but have come up short on finding much material. Therefore, I have tried implementing it myself based off information I found on apples documentation.
Long story short, I am getting success printed when I update my score, but no scores are actually being posted (or at-least no scores are showing up on the Game Center leaderboard when opened).
Before I show the code, one thing I have questioned is the fact that this game is still in development. In AppStoreConnect, the status of the leaderboard is "Not Live". Does this affect scores being posted?
Onto the code. I have created a GameCenter class which handles getting the leaderboards and posting scores to a specific leaderboard. I will post the code in whole, and will discuss below what is happening.
PLEASE VIEW ATTACHED TEXT TO SEE THE GAMECENTER CLASS!
GameCenter class - https://developer.apple.com/forums/content/attachment/0dd6dca8-8131-44c8-b928-77b3578bd970
In a different GameScene, once the game is over, I request to post a new high score to Game Center with this line of code:
GameCenter.shared.submitScore(id: GameCenterLeaderboards.HighScore.rawValue)
Now onto the logic of my code. For the longest time I struggled to figure out how to submit a score. I figured out that in Xcode 12, they deprecated a lot of functions that previously worked for me. Not is seems that we have to load all leaderboards (or the ones we want). That is the purpose behind the leaderboards private variable in the Game Center class.
On the start up of the app, I call authenticate player. Once this callback is reached, I call loadLeaderboards which will load the leaderboards for each string id in an enum that I have elsewhere. Each of these leaderboards will be created as a Leaderboard object, and saved in the private leaderboard array. This is so I have access to these leaderboards later when I want to submit a score.
Once the game is over, I am calling submitScore with the leaderboard id I want to post to. Right now, I only have a high score, but in the future I may add a parameter to this with the value so it works for other leaderboards as well. Therefore, no value is passed in since I am pulling from local storage which holds the high score.
submitScore will get the leaderboard from the private leaderboard array that has the same id as the one passed in. Once I get the correct leaderboard, I submit a score to that leaderboard. Once the callback is hit, I receive the output "Successfully submitted score to leaderboard". This looks promising, except for the fact that no score is actually posted.
At startup, I am calling updatePlayerHighScore, which is not complete - but for the purpose of my point, retrieves the high score of the player from the leaderboard and is printing it out to the console. It is printing out (0), meaning that no score was posted.
The last thing I have questions about is the context when submitting a score. According to the documentation, this seems to just be metadata that GameCenter does not care about, but rather something the developer can use. Therefore, I think I can cross this off as causing the problem.
I believe I implemented this correctly, but for some reason, nothing is posting to the leaderboard. This was ALOT, but I wanted to make sure I got all my thoughts down.
Any help on why this is NOT posting would be awesome! Thanks so much!
Mark
SceneDelegate's sceneWillEnterForeground and sceneDidEnterBackground methods are not called when app is moved to the background and back. It happens when Stage Manager is enabled and application is moved to the background using App Switcher (double tap on the home button).
Otherwise methods are called.
Started to reproduce since iOS26. Is not reproducible on iOS18.
I'm trying to understand how UIDevice.current.identifierForVendor behaves when an iOS app is restored via iCloud onto a different physical device.
Context
I'm building an app that needs to detect whether it’s running on a newly restored device (for example, after the user transfers their iPhone via iCloud setup).
To do this, I save the value of UIDevice.current.identifierForVendor?.uuidString in persistent storage (e.g., UserDefaults).
The question
If I install my app on Device A, store the identifierForVendor value, back up the device to iCloud,
and then restore that backup onto Device B, will the restored app see the same identifierForVendor value, or a new one?
More specifically:
Does iCloud backup/restore preserve the underlying “vendor” ID across devices?
Is the identifierForVendor tied only to the bundle identifier and vendor prefix, or also to the physical device hardware?
If the user deletes all apps from the same vendor, then restores them from iCloud, is the ID reset?
What I’ve found so far
Apple’s docs say:
“The value of this property is the same for apps that come from the same vendor running on the same device.
If the user deletes all of that vendor’s apps from the device and then reinstalls one or more of them, the value may change.”
However, it doesn’t explicitly mention what happens after iCloud restore onto a new device.
Goal
I want to know if it’s safe to use identifierForVendor to detect a new device context (e.g., trigger a refresh of a Firebase token when the user’s device changes).
Environment
iOS 17+ (latest)
Swift / Capacitor app bridge
Testing between iPhone 14 Pro → iPhone 15 Pro (iCloud restore)
I got several reports about our TestFlight app crashing unconditionally on 2 devices (iOS 18.1 and iOS 18.3.1) on app start with the following reason:
Termination Reason: DYLD 4 Symbol missing
Symbol not found: _$sScIsE4next7ElementQzSgyYa7FailureQzYKF
(terminated at launch; ignore backtrace)
The symbol in question demangles to
(extension in Swift):Swift.AsyncIteratorProtocol.next() async throws(A.Failure) -> A.Element?
Our deploy target is iOS 18.0, this symbol was introduced in Swift 6.0, we're using latest Xcode 16 now - everything should be working, but for some reason aren't.
Since this symbol is quite rarely used directly, I was able to pinpoint the exact place in code related to it. Few days ago I added the following code to our app library (details omitted):
public struct AsyncRecoveringStream<Base: AsyncSequence>: AsyncSequence {
...
public struct AsyncIterator: AsyncIteratorProtocol {
...
public mutating func next(isolation actor: isolated (any Actor)? = #isolation) async throws(Failure) -> Element? {
...
}
}
}
I tried to switch to Xcode 26 - it was still crashing on affected phone. Then I changed next(isolation:) to its older version, next():
public mutating func next() async throws(Failure) -> Element?
And there crashes are gone. However, this change is a somewhat problematic, since I either have to lower Swift version of our library from 6 to 5 and we loose concurrency checks and typed throws or I'm loosing tests due to Swift compiler crash. Performance is also affected, but it's not that critical for our case.
Why is this crash happening? How can I solve this problem or elegantly work around it?
Thank you!
2025-10-09_17-13-31.7885_+0100-23e00e377f9d43422558d069818879042d4c5c2e.crash
Why is there always such a long hang when first switching tabs or popping up the keyboard in SwiftUI Development?
Ever since Xcode Version 26.0.1 I cannot for the life of me make my buttons rectangular. They are all capsule (or oval) shaped. My interface was designed for square buttons but no matter what I do the issue stays the same. This is what I have (it's fairly barebones but would have worked before I believe):
@IBOutlet weak var PagesInterface: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
PagesInterface.layer.cornerRadius = 0
PagesInterface.layer.masksToBounds = true
}
Hi Apple Team and community,
We've noticed a change in how UITableView separators are rendered in iOS 26 (tested using Xcode 26.0), and we'd like to confirm if this is an intentional behaviour change or a potential bug.
Issue Description
In a .plain-style UITableView, the top separator line above the first cell in each section is no longer rendered in iOS 26. We've confirmed that this separator is also absent from the view hierarchy.
This issue did not occur in previous iOS versions (e.g., iOS 18), where the top separator above the first cell of a section was rendered as expected.
The issue doesn't occur for UITableView with no sections.
Expected Behavior
When using a .plain style UITableView, the standard top separator should appear above the first cell of each section, as part of the default system rendering.
Actual Behavior
In iOS 26, this top separator is missing, even though the rest of the separators render normally.
Environment
iOS version: iOS 26 (Simulator)
Xcode version: Xcode 26.0
Tested using: UIKit with Swift, both Storyboard and programmatic view setups
Sample app and screenshots:
Drive link: https://drive.google.com/drive/folders/1aoXeFHO_Sya-6Rvp0fZ0s2V4KLQucRMb?usp=sharing
Questions:
Is this a known change in rendering behavior for UITableView in iOS 26?
If not, is anyone else experiencing the same issue? We'd appreciate any insights or potential workarounds to restore the top separator in .plain-style table views.
Any clarification or guidance would be appreciated.
Thanks in advance!
Hi everyone,
We’re currently using CKSyncEngine to sync all our locally persisted data across user devices (iOS and macOS) via iCloud.
We’ve noticed something strange and reproducible:
On iOS, when the CKSyncEngine is initialized with manual sync behavior, both manual calls to fetchChanges() and sendChanges() happen nearly instantly (usually within seconds). Automatic syncing is also very fast.
On macOS, when the CKSyncEngine is initialized with manual sync behavior, fetchChanges() and sendChanges() are also fast and responsive.
However, once CKSyncEngine is initialized with automatic syncing enabled on macOS:
sendChanges() still appears to transmit changes immediately.
But automatic fetching becomes significantly slower — often taking minutes to pick up changes from the cloud, even when new data is already available.
Even manual calls to fetchChanges() behave as if they’re throttled or delayed, rather than performing an immediate fetch.
Our questions:
Is this delay in automatic (and post-automatic manual) fetch behavior on macOS expected, or possibly a bug?
Are there specific macOS constraints that impact CKSyncEngine differently than on iOS?
Once CKSyncEngine has been initialized in automatic mode, is fetchChanges() no longer treated as a truly manual trigger?
Is there a recommended workaround to enable fast sync behavior on macOS — for example, by sticking to manual sync configuration and triggering sync using a CKSubscription-based mechanism when remote changes occur?
Any guidance, clarification, or experiences from other developers (or Apple engineers) would be greatly appreciated — especially regarding maintaining parity between iOS and macOS sync performance.
Thanks in advance!