A few questions. One, can I safely upgrade to my project to Swift 6.2 without having to require iOS 26+? Two, where do I actually make the upgrade. This is what I see in build settings:
6.2 is not available in the dropdown?
Swift
RSS for tagSwift is a powerful and intuitive programming language for Apple platforms and beyond.
Posts under Swift tag
200 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
Hi,
in our Xcode project we have a Tooling package, which defines build tool plugins for generating compile time safe constants for our localization strings as well as assets using swiftgen.
This is working very well in Xcode 16, but fails in Xcode 26 beta 1 and beta 2 as well.
The failure is specifically:
unsupported configuration: the aggregate target 'Localization' has package dependencies, but targets that build for different platforms depend on it.
I've reduced this to a minimal sample project, which you can find here.. To reproduce: Open the Repro workspace, that is attached in Xcode. Try to build TestyPackage. You'll see the error.
I've filed this bug during WWDC week, but no feedback yet and no solution in Xcode 26 beta 2. Here's the feedback number, in case you have this too and want to file a duplicate: FB17934050.
Does anyone else have this issue and perhaps a solution?
In my application, I have NavigationStack presented as a sheet, and I intend to dynamically adjust its height while pushing views within it. I'm utilizing a global observable variable to manage the height and everything works fine except that the height changes abruptly without any animation. It abruptly transitions from one height to another.
The issue can be reproduced using the following code:
#Preview {
@Previewable @State var height: CGFloat = 200
Text("Parent View")
.sheet(isPresented: .constant(true)) {
NavigationStack {
Form {
NavigationLink("Button") {
RoundedRectangle(cornerRadius: 20)
.fill(Color.blue)
.frame(height: 200)
.navigationTitle("Child")
.onAppear {
withAnimation {
height = 300
}
}
}
}
.navigationTitle("Parent")
.navigationBarTitleDisplayMode(.inline)
.presentationDetents([.height(height)])
.onAppear {
withAnimation {
height = 150
}
}
}
}
}
Merhaba,
iOS üzerinde bir sözleşme onay uygulaması geliştiriyorum. Kullanıcıların dijital ortamda sözleşmeleri okuyup onaylaması gerekiyor. Ancak hukuki geçerlilik konusunda bazı tereddütlerim vardı.
Bursa’da yaşayan biri olarak bu konuda bir avukata danışmam gerekti. Şans eseri https://www.avukatcanata.com ile karşılaştım ve hem bireysel hem ticari sözleşmeler konusunda gerçekten çok net açıklamalar sundular. Özellikle elektronik imza ve KVKK uyumu hakkında verdikleri bilgiler sayesinde projemi yasal zemine oturtabildim.
Eğer bu tarz uygulamalar geliştiriyorsanız, mutlaka bir hukukçu görüşü alın. Yanlış bir adım size veya kullanıcınıza ciddi sonuçlar doğurabilir.
Teşekkürler 🍏
In scope of one of our project we've faced an issue with constant crashes when integrating C++ library in Swift code using Swift/C++ interoperability.
Investigating the root causes of the issue we've discovered that with new version of Swift bug was introduced.
Long story short: for strings bigger than 27 symbols memory is feed incorrectly that causes the crashes.
By creating this post I wanted to draw community's attention to the problem and promote it to be solved quicker as for now it is not addressed.
Hello guys!
I faced a problem with building...
My device suddenly updated to iOS 15.4.1, my Xcode was 13.2 and I had to update it to the latest version (13.3.1) to build the app. After the update, I had a few problems which were successfully solved but one of them stopped me for a few hours. The problem is with Bridging Headers or Swift Compiler, I really don't know what I did badly, and what causes problems.
On several forums I often read that is important to set:
Build Settings > Build Options > Build Libraries for Distribution
But in any case it doesn't work, on yes:
error: using bridging headers with module interfaces is unsupported
on no:
(line with import framework SWXMLHash) /Users/blablabla/SSLModel.swift:9:8: error: module compiled with Swift 5.5.1 cannot be imported by the Swift 5.6 compiler: /Users/blablabla2/Build/Products/Debug-iphoneos/SWXMLHash.framework/Modules/SWXMLHash.swiftmodule/arm64-apple-ios.swiftmodule
import SWXMLHash
It will be important that I use Carthage.
What should I do?
Clone all 10 frameworks that I use and re-build them with a new Xcode which includes compiler 5.6? That may be a bad solution... Any answers on similar topics don't help..
Hi everyone,
I’m working on an iOS project where an iPhone needs to connect to external scanners (dedicated hardware devices) over Wi-Fi. The goal is to:
Discover available Wi-Fi networks from the scanner devices (broadcasting their own networks).
Allow the user to seamlessly connect to the chosen scanner network.
Network Discovery:
Is there a way to programmatically list available Wi-Fi networks (SSIDs) on iOS without private APIs?
If not, are there workarounds (e.g., Bonjour/mDNS)?
Seamless Connection:
As I see, we can use NEHotspotConfigurationManager to connect to and disconnect from specified networks and there will always be a system alert asking about do we really want to join this network
Hardware/Firmware/Software Alternatives:
If iOS restrictions prevent this, what alternatives exist? For example:
Hardware: Scanners supporting Bluetooth LE for initial pairing, then Wi-Fi provisioning.
Firmware: Scanners acting as clients on the same network as the iPhone (e.g., via user’s home/office Wi-Fi).
Software: A companion app for the scanner that shares network credentials via QR code/NFC, or a local web server on the scanner for setup.
Context:
Target: iOS 16+
No jailbreaking; App Store compliance is a must.
Scanners can be configured to act as APs or clients.
On an app that was using the old API for In-App Purchases (StoreKit 1). The app is already published on the App Store. The purchase is non-consumable.
While trying to migrate to StoreKit 2, I'm unable to restore purchases.
Specifically displaying and purchasing products works as expected, but when deleting and reinstalling the app, and then trying to restore purchases I can't do it.
I'm trying to restore them using the new APIs but it doesn't seem to be working.
What I have tried so far:
I'm listening for transaction updates during the whole lifetime of the app, with:
Task.detached {
for await result in Transaction.updates {
if case let .verified(safe) = result {
}
}
}
I have a button that calls this method, but other than prompting to log in again with the Apple ID it doesn't seem to have any effect at all:
try? await AppStore.sync()
This doesn't return any item
for await result in Transaction.currentEntitlements {
if case let .verified(transaction) = result {
}
}
This doesn't return any item
for await result in Transaction.all {
if case let .verified(transaction) = result {
}
}
As mentioned before I'm trying this after purchasing the item and deleting the app. So I'm sure it should be able to restore the purchase.
Am trying this both with a Configuration.storekit file on the simulator, and without it on a real device, in the Sandbox Environment.
Has anyone being able to restore purchases using StoreKit 2?
PD: I already filed a feedback report on Feedback Assistant, but so far the only thing that they have replied is:
Because StoreKit Testing in Xcode is a local environment, and the data is tied to the app, when you delete the app you're also deleting all the transaction data for that app in the Xcode environment. The code snippets provided are correct usage of the API.
So yes, using a Configuration.storekit file won't work on restoring purchases, but if I can't restore them on the Sandbox Environment I'm afraid that this won't work once released, leaving my users totally unable to restore what they have already purchased.
My framework has private Objective-C API that is only used within the framework. It should not be exposed in the public interface (so it shouldn't be imported in the umbrella header).
To expose this API to Swift that's within the framework only the documentation seems to indicate that this needs to be imported in the umbrella header?
Import Code Within a Framework Target
To use the Objective-C declarations in files in the same framework target as your Swift code, configure an umbrella header as follows:
1.Under Build Settings, in Packaging, make sure the Defines Module setting for the framework target is set to Yes.
2.In the umbrella header, import every Objective-C header you want to expose to Swift.
Swift sees every header you expose publicly in your umbrella header. The contents of the Objective-C files in that framework are automatically available from any Swift file within that framework target, with no import statements. Use classes and other declarations from your Objective-C code with the same Swift syntax you use for system classes.
I would imagine that there must be a way to do this?
I am working on an iOS project using Xcode 16.0 that leverages multiple Swift packages. Among these, I have a Shared Package that contains reusable code and is linked to several top-level feature packages (e.g., VideoPlayer, VideoEditor, etc.).
The Shared Package includes a Swift Package Manager plugin for linting code standards, which is designed to execute during its own build process. However, when building a top-level package (e.g., VideoPlayer), the Shared Package is also built as part of the dependency graph. During this process, the linting plugin in the Shared Package is executed unnecessarily, even though the intent is to only build the Shared Package's code.
This behavior results in a significant increase in build times for the top-level packages, as the linting plugin is executed every time the Shared Package is built indirectly.
Key Details:
Xcode Version: 16.0
Swift Package Manager: Used for dependency management.
Issue: The linting plugin in the Shared Package executes during the build of top-level packages, increasing build times.
Expected Behaviour: The plugin should only execute when the Shared Package is built directly, not when it is built as a dependency of a top-level package.
I would like to know if there is a way to configure the Shared Package or the Swift Package Manager to prevent the plugin from executing when the Shared Package is built as a dependency of a top-level package, while still allowing the plugin to run when the Shared Package is built directly.
Any guidance, configuration tips, or best practices to address this issue would be greatly appreciated.
I have the following method to insert @mentions to a text field:
func insertMention(user: Token, at range: NSRange) -> Void {
let tokenImage: UIImage = renderMentionToken(text: "@\(user.username)")
let attachment: NSTextAttachment = NSTextAttachment()
attachment.image = tokenImage
attachment.bounds = CGRect(x: 0, y: -3, width: tokenImage.size.width, height: tokenImage.size.height)
attachment.accessibilityLabel = user.username
attachment.accessibilityHint = "Mention of \(user.username)"
let attachmentString: NSMutableAttributedString = NSMutableAttributedString(attributedString: NSAttributedString(attachment: attachment))
attachmentString.addAttribute(.TokenID, value: user.id, range: NSRange(location: 0, length: 1))
attachmentString.addAttribute(.Tokenname, value: user.username, range: NSRange(location: 0, length: 1))
let mutableText: NSMutableAttributedString = NSMutableAttributedString(attributedString: textView.attributedText)
mutableText.replaceCharacters(in: range, with: attachmentString)
mutableText.append(NSAttributedString(string: " "))
textView.attributedText = mutableText
textView.selectedRange = NSRange(location: range.location + 2, length: 0)
mentionRange = nil
tableView.isHidden = true
}
When I use XCode's accessibility inspector to inspect the text input, the inserted token is not read by the inspector - instead a whitespace is shown for the token. I want to set the accessibility-label to the string content of the NSTextAttachment. How?
For many years I've had the following code to access the active objects of a table view in my App Store app:
class MyViewController: NSViewController: NSMenuItemValidation {
private var tableView: NSTableView!
private var objects = [MyObject]()
func numberOfRows(in tableView: NSTableView) -> Int {
return objects.count
}
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
// make view for row
}
private var activeObjects: [MyObject] {
return tableView?.activeRowIndexes.map({ objects[$0] }) ?? []
}
func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
let activeObjects = self.activeObjects
...
}
}
extension NSTableView {
var activeRowIndexes: IndexSet {
return clickedRow == -1 || selectedRowIndexes.contains(clickedRow) ? selectedRowIndexes : IndexSet(integer: clickedRow)
}
}
In one of the recent updates, I wanted to add some kind of header to the table view, so I decided to add a row at the beginning and offset the indexes by 1.
func numberOfRows(in tableView: NSTableView) -> Int {
return objects.count + 1
}
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
if row == 0 {
// make header view
} else {
// make view for row - 1
}
}
private var activeObjects: [MyObject] {
return tableView?.activeRowIndexes.subtracting(IndexSet(integer: 0)).map({ objects[$0 - 1] }) ?? []
}
But since I added this change, Xcode regularly downloads crash reports from clients crashing during menu item validation in IndexSet.map with reason Code 5 Trace/BPT trap: 5. I assumed that I was accessing an invalid array index, so I added some debug code: the crash report would then show the invalid index beside the crashed thread's name.
private var activeObjects: [MyObject] {
return tableView?.activeRowIndexes.subtracting(IndexSet(integer: 0)).map({ i in
if !objects.indices.contains(i - 1) {
Thread.current.name = (Thread.current.name ?? "") + ". Invalid index \(i - 1) for count \(objects.count)"
preconditionFailure()
}
return objects[i - 1]
}) ?? []
}
But the crash reports for this new app version look just like the old ones and the thread name is not changed. Indeed, when recreating an invalid index access on my Mac, the crash report mentions Array._checkSubscript(_:wasNativeTypeChecked:), which does not appear in the crash reports downloaded by Xcode.
Manually symbolicating the crash report also doesn't give any more information: all lines referring to my app code are resolved to either /<compiler-generated>:0 or MyViewController.swift:0.
Apparently the problem is not an invalid array index, but something else. Does anybody have a clue what the problem could be?
(Note: the crash report mentions Sequence.compactMap because now I'm effectively calling tableView?.activeRowIndexes.compactMap, but the same crash happened before when calling IndexSet.map, which would appear in the crash report as Collection.map.)
crash2.crash
Hi team, is there a native way to detect if a change has been made to biometrics using FaceID or TouchID? Thanks in advance.
Hi everyone,
I'm developing a Capacitor plugin to display an RTSP video stream using MobileVLCKit on iOS. The Android side works perfectly, but I can’t get the iOS plugin to work — it seems my Swift file is not being detected or recognized, even though I’ve followed the official steps.
What works:
I followed the Capacitor Plugin Development Guide.
I implemented the Android version of the plugin in Java inside the android/ folder. Everything works perfectly from Angular: the plugin is recognized and calls execute correctly.
The issue on iOS:
I implemented the iOS part in Swift, using the official MobileVLCKit documentation.
I initially placed my RtspVlcPlugin.swift file in the plugin’s iOS folder, as the docs suggest.
Then I moved it directly into the main app’s ios/App/App/ folder next to AppDelegate.swift and tried manual registration.
The problem:
Even though I manually register the plugin with:
if let bridge = self.window?.rootViewController as? CAPBridgeViewController {
bridge.bridge?.registerPluginInstance(RtspVlcPlugin())
print("✅ Plugin RtspVlcPlugin registered manually.")
}
It prints the registration message just fine.
BUT from Angular, the plugin is not recognized: Capacitor.Plugins.RtspVlcPlugin has no methods, and I get this error:
"code":"UNIMPLEMENTED"
I also tried declaring @objc(RtspVlcPlugin) and extending CAPPlugin.
I’ve verified RtspVlcPlugin.swift is added to the target and compiled.
The Swift file doesn’t seem to register or expose any methods to Angular.
I even tried adding the code without using a plugin at all — just creating a Swift class and using it via the AppDelegate, but it still doesn't expose any callable methods.
My Swift code (RtspVlcPlugin.swift):
import Capacitor
import MobileVLCKit
@objc(RtspVlcPlugin)
public class RtspVlcPlugin: CAPPlugin, VLCMediaPlayerDelegate {
var mediaPlayer: VLCMediaPlayer?
var containerView: UIView?
var spinner: UIActivityIndicatorView?
@objc func iniciar(_ call: CAPPluginCall) {
guard
let urlStr = call.getString("url"),
let x = call.getDouble("x"),
let y = call.getDouble("y"),
let w = call.getDouble("width"),
let h = call.getDouble("height"),
let url = URL(string: urlStr)
else {
call.reject("Missing parameters")
return
}
DispatchQueue.main.async {
self.containerView?.removeFromSuperview()
let cont = UIView(frame: CGRect(x: x, y: y, width: w, height: h))
cont.backgroundColor = .black
cont.layer.cornerRadius = 16
cont.clipsToBounds = true
let sp = UIActivityIndicatorView(style: .large)
sp.center = CGPoint(x: w/2, y: h/2)
sp.color = .white
sp.startAnimating()
cont.addSubview(sp)
self.spinner = sp
self.containerView = cont
self.bridge?.viewController?.view.addSubview(cont)
let player = VLCMediaPlayer()
player.delegate = self
player.drawable = cont
player.media = VLCMedia(url: url)
self.mediaPlayer = player
player.play()
call.resolve()
}
}
@objc func cerrar(_ call: CAPPluginCall) {
DispatchQueue.main.async {
self.mediaPlayer?.stop()
self.mediaPlayer = nil
self.spinner?.stopAnimating()
self.spinner?.removeFromSuperview()
self.spinner = nil
self.containerView?.removeFromSuperview()
self.containerView = nil
call.resolve()
}
}
public func mediaPlayerStateChanged(_ aNotification: Notification!) {
guard let player = mediaPlayer,
player.state == .playing,
let sp = spinner else { return }
DispatchQueue.main.async {
sp.stopAnimating()
sp.removeFromSuperview()
self.spinner = nil
}
}
}
In the Angular project, I’m using the plugin by manually registering it with registerPlugin from @capacitor/core. Specifically, in the service where I need it, I do the following:
import { registerPlugin } from '@capacitor/core';
const RtspVlcPlugin: any = registerPlugin('RtspVlcPlugin');
After this, I try to call the methods defined in the iOS plugin, like RtspVlcPlugin.iniciar({ ... }), but I get an UNIMPLEMENTED error, which suggests that the plugin is not exposing its methods properly to the Angular/Capacitor environment. That makes me believe the problem lies in how the Swift file is integrated or registered, rather than how it is used from Angular.
I’d appreciate any guidance on how to properly expose a Swift-based Capacitor plugin’s methods so that they are accessible from Angular. Is there any additional registration step or metadata I might be missing on the iOS side?
Hi everyone,
I’m working on a Capacitor app built with Angular, and I’m trying to call a Swift class directly from the root of the iOS project (next to AppDelegate.swift) without using a full Capacitor plugin structure.
The Swift file is called RtspVlcPlugin.swift and looks like this:
import Capacitor
@objc(RtspVlcPlugin)
public class RtspVlcPlugin: CAPPlugin {
@objc func iniciar(_ call: CAPPluginCall) {
call.resolve()
}
}
In AppDelegate.swift I register it like this:
if let bridge = self.window?.rootViewController as? CAPBridgeViewController {
bridge.bridge?.registerPluginInstance(RtspVlcPlugin())
print("✅ RtspVlcPlugin registered.")
}
The registration message prints correctly in Xcode logs.
But from Angular, when I try to call it like this:
import { registerPlugin } from '@capacitor/core';
const RtspVlcPlugin: any = registerPlugin('RtspVlcPlugin');
RtspVlcPlugin.iniciar({ ... });
I get this error:
{"code":"UNIMPLEMENTED"}
So, even though the plugin is registered manually, it’s not exposing any methods to the Angular/Capacitor runtime.
My question is:
What is the correct way to access a manually created Swift class (in the root of the iOS project) from Angular via Capacitor?
Thanks in advance!
I have a transformation function that takes in data, executes some instructions, and returns an output. This function is dynamic and not shipped with the binary. Currently, I’m executing it using JavaScriptCore.JSContext, which works well, but the function itself is written in JavaScript.
Is there a way to achieve something similar using Swift – such as executing a dynamic Swift script, either directly or through other means? I know this is possible on macOS, but I’m not sure about iOS. I’ve also heard that extensions might open up some possibilities here. Any insights or alternative approaches would be appreciated.
Our app provides a calendar that integrates with the default calendar app. Specifically, we use iOS EventKit to perform CRUD operations on calendar data.
Recently, we have received reports from users that all of their events have disappeared. However, after reviewing our implementation and logs, we have not been able to identify the cause. Some users have also reported that all data in their default calendar app has disappeared as well.
Does anyone have any idea what might be causing this?
To delete an event within our app, users must press the delete button and then confirm the deletion in a dialog. Additionally, it is not possible to delete more than two events at once.
We've seen many people in the community discussing a bug where calendar events disappear after updating to iOS 18. If you have any information about when or why this happens, we'd appreciate it if you could share your insights.
I'd like to know if there is a new property we can use in the definition of a Swift Package in the new Xcode 26, where we can set the whole package to run on Main Actor, as we have it in our apps for Xcode 26.
I've been testing the safeAreaBar modifier to develop a custom tab bar. From my understanding, this should enable the .scrollEdgeEffectStyle to work with this bar, but I don't see any effect.
Could you please clarify the difference between safeAreaBar and safeAreaInset?
Hello,
I'm getting this error when launching a SpriteKit Swift game in iOS 18+ on an iPhone 11 Pro, whose shell is partly damaged in the back:
CHHapticEngine.mm:1206 -[CHHapticEngine doStartWithCompletionHandler:]_block_invoke: ERROR: Player start failed: The operation couldn’t be completed. (com.apple.CoreHaptics error 1852797029.)
Haptics do not work on this device, due to the damaged shell, so some error — which obviously occurs when calling start(completionHandler:) — is definitely expected; what is not expected is the main thread sometimes blocking for up to 5 seconds — although the method is not called from the main thread... the error itself is always displayed from some other secondary (system) thread. During this time, the main thread does not access the haptics engine at all; on average, it blocks once every four or five launches. In each launch (blocking or not), the 'nope' error is displayed ~5 seconds after trying to start the engine.
After going nuts with all kinds of breakpoints and instrumentation, I'm at a loss as to why the main thread would sometimes block...
Ideas, anyone?
Thank you,
D.