I have developed a Swift macro called @CodableInit in the SwiftCodableMacro module, and I’m able to use it successfully in my main project.
Here’s an example usage:
import SwiftCodableMacro
@CodableInit // This is for Codable macros
public class ErrorMonitoringWebPlugin {
public var identifier: UUID = UUID()
// MARK: - Codable
required public init(from decoder:Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
identifier = try values.decode(UUID.self, forKey: .identifier)
}
}
However, when I try to write a unit test for the ErrorMonitoringWebPlugin class, I encounter an issue. Here's the test case:
func testCodableSubjectIdentifierShouldEqualDecodedSubjectIdentifier() {
self.measure {
let encoder = JSONEncoder()
let data = try? encoder.encode(subject)
//Here I am getting this error
Class 'JSONEncoder' requires that 'ErrorMonitoringWebPlugin' conform to 'Encodable'
let decoder = JSONDecoder()
let decodedSubject = try? decoder.decode(ErrorMonitoringWebPlugin.self, from: data!)
XCTAssertEqual(subject.identifier, decodedSubject?.identifier)
}
}
The compiler throws an error saying:
Class 'JSONEncoder' requires that 'ErrorMonitoringWebPlugin' conform to 'Encodable'
Even though the @CodableInit macro is supposed to generate conformance, it seems that this macro-generated code is not visible or active inside the test target.
How can I ensure that the @CodableInit macro (from SwiftCodableMacro) is correctly applied and recognized within the XCTest target of my main project?
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
Feedback id: FB16140301
Below are the steps to reproduce the bug in Contacts app.
Open Contacts app.
Now search for a contact and didSelect that contact.
Now slightly hold swipe right(from view's center leading position) as to pop the view but not fully swipe, now release the finger and you can see the back nav bar button missing and tapping the back button position also doesn't perform dismiss action.
Now do fully swipe from left to right to dismiss(pop) current view.
Here you can see the search bar missing.-> That's the bug.
Hey everyone,
I have a problem with an app im creating. The code doesn't have any errors but the console has this that pops up:
Snapshot request 0x1054191d0 complete with error: <NSError: 0x10541a970; domain: FBSSceneSnapshotErrorDomain; code: 4; "an unrelated condition or state was not satisfied"> {
NSLocalizedDescription = an error occurred during a scene snapshotting operation;
}
Basically when showing a view using the .fullScreenCover modifier, it has no background anymore, any other UI elements are still shown but the view under it is also still shown.
I'm working on an iOS/iPadOS app and need to determine programmatically whether the device is a Shared iPad as configured through Apple School Manager (ASM).
Shared iPads allow multiple users to sign in with Managed Apple IDs and are typically used in educational environments. I want to identify this configuration at runtime within my app.
I’ve looked into UIDevice, NSProcessInfo, and MDM-related APIs but haven't found a reliable way to detect whether the current device is a Shared iPad.
Is there an API or method to check if the current iPad is configured as a Shared iPad (via ASM)?
Any guidance or code examples would be appreciated.
@Observable seems not to work well with generic typed throw.
The following code using @Observable with non-generic typed throw builds good:
@Observable
class ThrowsLoadingViewModel<R, E: Error> {
private(set) var isLoading = true
private(set) var error: E? = nil
private(set) var data: R? = nil
private var task: () throws(Error) -> R
init(task: @escaping () throws(E) -> R) {
self.task = task
}
func load() {
do throws(Error) {
self.data = try task()
} catch {
// self.error = error
}
self.isLoading = false
}
}
But if I change Line 7 and 14 to generic, it'll breaks the build with a "Command SwiftCompile failed with a nonzero exit code" message :
@Observable
class ThrowsLoadingViewModel<R, E: Error> {
private(set) var isLoading = true
private(set) var error: E? = nil
private(set) var data: R? = nil
private var task: () throws(E) -> R
init(task: @escaping () throws(E) -> R) {
self.task = task
}
func load() {
do throws(E) {
self.data = try task()
} catch {
// self.error = error
}
self.isLoading = false
}
}
A the same time, if I remove @Observable, the generic typed throw works again:
class ThrowsLoadingViewModel<R, E: Error> {
private(set) var isLoading = true
private(set) var error: E? = nil
private(set) var data: R? = nil
private var task: () throws(E) -> R
init(task: @escaping () throws(E) -> R) {
self.task = task
}
func load() {
do throws(E) {
self.data = try task()
} catch {
// self.error = error
}
self.isLoading = false
}
}
Currently the possible solution seems to fall back to use ObservableObject...
With Swift being brought to new places, is anyone working on interoperability with PHP? I'd love to replace much of my PHP and Javascript web code with Swift (and ideally SwiftUI for UI design). Are there any projects/people working in this space?
I'm very unpleased to have found out the hard way, that
vDSP.FFT&lt;T&gt; where T : vDSP_FourierTransformable
and its associated vDSP_FourierTransformFunctions,
only does real-complex conversion!!!
This is horribly misleading - the only hint that it calls vDSP_fft_zrop() (split-complex real-complex out-of-place) under the hood, not vDSP_fft_zop()[1], is "A 1D single- and double-precision fast Fourier transform." - instead of "a single- and double-precision complex fast Fourier transform". Holy ******* ****.
Just look at how people miss-call this routine. Poor him, realizing he had to log2n+1 lest only the first half of the array was transformed, not understanding why [2].
And poor me, having taken days investigating why a simple Swift overlay vDSP.FFT.transform may execute at 1.4x the speed of vDSP_fft_zopt(out-of-place with temporary buffer)! [3]
[1]: or better, vDSP_fft_zopt with the temp buffer alloc/dealloc taken care of, for us
[2]: for real-complex conversion, say real signal of length 16. log2n is 4 no problem, but then the real and imaginary vectors are both length 8. Also, vDSP_fft only works on integer powers of 2, so he had to choose next integer power of 2 (i.e. 1&lt;&lt;(log2n-1)) instead of plain length for his internal arrays.
[3]: you guessed it. fft_zrop(log2n-1, ...) vs. fft_zop(log2n, ...). Half the problem size lol.
Now we have vDSP.DiscreteFourierTransform, which wraps vDSP_DFT routines and "calls FFT routines when the size allows it", and works too for interleaved complexes. Just go all DFT, right?
if let setup_f = try? vDSP.DiscreteFourierTransform(previous: nil, count: 8, direction: .forward, transformType: .complexComplex, ofType: DSPComplex.self) {
// Done forward transformation
// and scaled the results with 1/N
// How about going reverse?
if let setup_r = try? vDSP.DiscreteFourierTransform(previous: setup_f, count: 8, direction: .inverse, transformType: .complexComplex, ofType: DSPComplex.self) {
// Error: cannot convert vDSP.DiscreteFourierTransform&lt;DSPComplex&gt; to vDSP.DiscreteFourierTransform&lt;Float&gt;
// lolz
}
}
This API appeared in macOS 12. 3 years later nobody have ever noticed. I'm at a loss for words.
The project builds successfully but unable to archive project on Xcode 26.
error: "Command SwiftCompile failed with a nonzero exit code"
I'm running into a seemingly unsolvable compile problem with the new Xcode 26 and Swift 6.2.
Here's the issue.
I've got this code that was working before:
NSAnimationContext.runAnimationGroup({(context) -> Void in
context.duration = animated ? 0.5 : 0
clipView.animator().setBoundsOrigin(p)
}, completionHandler: {
self.endIgnoreFrameChangeEvents()
})
It's very simple. The clipView is a scrollView.contentView, and "animated" is a bool, and p is an NSPoint
It captures those things, scrolls the clip view (animating if needed) to the point, and then calls a method in self to signal that the animation has completed.
I'm getting this error:
Call to main actor-isolated instance method 'endIgnoreFrameChangeEvents()' in a synchronous nonisolated context
So, I don't understand why so many of my callbacks are getting this error now, when they worked before, but it is easy to solve. There's also an async variation of runAnimationGroup. So let's use that instead:
Task {
await NSAnimationContext.runAnimationGroup({(context) -> Void in
context.duration = animated ? 0.5 : 0
clipView.animator().setBoundsOrigin(p)
})
self.endIgnoreFrameChangeEvents()
}
So, when I do this, then I get a new error. Now it doesn't like the first enclosure. Which it was perfectly happy with before.
Here's the error:
Sending value of non-Sendable type '(NSAnimationContext) -> Void' risks causing data races
Here are the various overloaded definitions of runAnimationGroup:
open class func runAnimationGroup(_ changes: (NSAnimationContext) -> Void, completionHandler: (@Sendable () -> Void)? = nil)
@available(macOS 10.7, *)
open class func runAnimationGroup(_ changes: (NSAnimationContext) -> Void) async
@available(macOS 10.12, *)
open class func runAnimationGroup(_ changes: (NSAnimationContext) -> Void)
The middle one is the one that I'm trying to use. The closure in this overload isn't marked sendable. But, lets try making it sendable now to appease the compiler, since that seems to be what the error is asking for:
Task {
await NSAnimationContext.runAnimationGroup({ @Sendable (context) -> Void in
context.duration = animated ? 0.5 : 0
clipView.animator().setBoundsOrigin(p)
})
self.endIgnoreFrameChangeEvents()
}
So now I get errors in the closure itself. There are 2 errors, only one of which is easy to get rid of.
Call to main actor-isolated instance method 'animator()' in a synchronous nonisolated context
Call to main actor-isolated instance method 'setBoundsOrigin' in a synchronous nonisolated context
So I can get rid of that first error by capturing clipView.animator() outside of the closure and capturing the animator. But the second error, calling setBoundsOrigin(p) - I can't move that outside of the closure, because that is the thing I am animating! Further, any property you're going to me animating in runAnimationGroup is going to be isolated to the main actor.
So now my code looks like this, and I'm stuck with this last error I can't eliminate:
let animator = clipView.animator()
Task {
await NSAnimationContext.runAnimationGroup({ @Sendable (context) -> Void in
context.duration = animated ? 0.5 : 0
animator.setBoundsOrigin(p)
})
self.endIgnoreFrameChangeEvents()
}
Call to main actor-isolated instance method 'setBoundsOrigin' in a synchronous nonisolated context
There's something that I am not understanding here that has changed about how it is treating closures. This whole thing is running synchronously on the main thread anyway, isn't it? It's being called from a MainActor context in one of my NSViews. I would expect the closure in runAnimationGroup would need to be isolated to the main actor, anyway, since any animatable property is going to be marked MainActor.
How do I accomplish what I am trying to do here?
One last note: There were some new settings introduced at WWDC that supposedly make this stuff simpler - "Approchable Concurrency". In this example, I didn't have that turned on. Turning it on and setting the default to MainActor does not seem to have solved this problem.
(All it does is cause hundreds of new concurrency errors in other parts of my code that weren't there before!)
This is the last new error in my code (without those settings), but I can't see any way around this one. It's basically the same error as the others I was getting (in the callback closures), except with those I could eliminate the closures by changing APIs.
When I try to use an entity created in a CoreData, it gives me: 'PlayerData' is ambiguous for type lookup in this context
I have the following function
private func SetupLocaleObserver ()
{
NotificationCenter.default.addObserver (
forName: NSLocale.currentLocaleDidChangeNotification,
object: nil,
queue: .main
) {_ in
print ("Locale changed to: \(Locale.current.identifier)");
}
}
I call this function inside the viewDidLoad () method of my view controller. The expectation was that whenever I change the system or app-specific language preference, the locale gets changed, and this change triggers my closure which should print "Locale changed to: " on the console.
However, the app gets terminated with a SIGKILL whenever I change the language from the settings. So, it is observed that sometimes my closure runs, while most of the times it does not run - maybe the app dies even before the closure is executed.
So, the question is, what is the use of this particular notification if the corresponding closure isn't guaranteed to be executed before the app dies? Or am I using it the wrong way?
In WWDC25 video 284: Build a UIKit app with the new design, there is mention of a cornerConfiguration property on UIVisualEffectView. But this properly isn't documented and Xcode 26 isn't aware of any such property.
I'm trying to replicate the results of that video in the section titled Custom Elements starting at the 19:15 point. There is a lot of missing details and typos in the code associated with that video.
My attempts with UIGlassEffect and UIViewEffectView do not result in any capsule shapes. I just get rectangles with no rounded corners at all.
As an experiment, I am trying to recreate the capsule with the layers/location buttons in the iOS 26 version of the Maps app.
I put the following code in a view controller's viewDidLoad method
let imgCfgLayer = UIImage.SymbolConfiguration(hierarchicalColor: .systemGray)
let imgLayer = UIImage(systemName: "square.2.layers.3d.fill", withConfiguration: imgCfgLayer)
var cfgLayer = UIButton.Configuration.plain()
cfgLayer.image = imgLayer
let btnLayer = UIButton(configuration: cfgLayer, primaryAction: UIAction(handler: { _ in
print("layer")
}))
var cfgLoc = UIButton.Configuration.plain()
let imgLoc = UIImage(systemName: "location")
cfgLoc.image = imgLoc
let btnLoc = UIButton(configuration: cfgLoc, primaryAction: UIAction(handler: { _ in
print("location")
}))
let bgEffect = UIGlassEffect()
bgEffect.isInteractive = true
let bg = UIVisualEffectView(effect: bgEffect)
bg.contentView.addSubview(btnLayer)
bg.contentView.addSubview(btnLoc)
view.addSubview(bg)
btnLayer.translatesAutoresizingMaskIntoConstraints = false
btnLoc.translatesAutoresizingMaskIntoConstraints = false
bg.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
btnLayer.leadingAnchor.constraint(equalTo: bg.contentView.leadingAnchor),
btnLayer.trailingAnchor.constraint(equalTo: bg.contentView.trailingAnchor),
btnLayer.topAnchor.constraint(equalTo: bg.contentView.topAnchor),
btnLoc.centerXAnchor.constraint(equalTo: bg.contentView.centerXAnchor),
btnLoc.topAnchor.constraint(equalTo: btnLayer.bottomAnchor, constant: 15),
btnLoc.bottomAnchor.constraint(equalTo: bg.contentView.bottomAnchor),
bg.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor),
bg.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 40),
])
The result is pretty close other than the complete lack of capsule shape.
What changes would be needed to get the capsule shape? Is this even the proper approach?
Hi,
I’m trying to use the new InlineArray type, but noticed that it is unfortunately only available on macOS 26 and not on macOS 15 and others. As this is quite an essential type, I was wondering if this is intended or will this change in later beta’s? Not having it available on older Darwin platforms would severily limit it’s usage in the coming years.
Thanks!
Last night my iPhone game crashed while running in debug mode on my iPhone. I just plugged it into my Mac, and was able to find the ips file. The stack trace shows the function in my app where it crashed, and then a couple of frames in libswiftCore.dylib before an assertion failure.
My question is - I've got absolutely no idea what the assertion failure actually was, all I have is...
0 libswiftCore.dylib 0x1921412a0 closure #1 in closure #1 in closure #1 in _assertionFailure(_:_:file:line:flags:) + 228
1 libswiftCore.dylib 0x192141178 closure #1 in closure #1 in _assertionFailure(_:_:file:line:flags:) + 327
2 libswiftCore.dylib 0x192140b4c _assertionFailure(_:_:file:line:flags:) + 183
3 MyGame.debug.dylib 0x104e52818 SentryBrain.takeTurn(actor:) + 1240
...
How do I figure out what the assertion failure was that triggered the crash? How do I figure out what line of code in takeTurn(...) triggered the failing assertion failure?
The swift syntax compilation reported an error.
as follows
How should I be compatible
Hi all,
I’m running into a persistent build issue with my Swift project ORSOFINAL after migrating from Xcode stable to Xcode-beta.app (June 2025 version).
⸻
💥 Errors displayed:
1. C99 was enabled in PCH file but is currently disabled
2.
module file .../ModuleCache.noindex/SwiftShims-AXUM98L131W4...pcm
cannot be loaded due to a configuration mismatch with the current compilation
3. missing required module 'SwiftShims'
⸻
🛠 What I’ve already tried:
• xcode-select -s /Applications/Xcode-beta.app/Contents/Developer
• Deleted ~/Library/Developer/Xcode/DerivedData, ModuleCache.noindex, Archives, and Products
• Ran sudo xcodebuild -runFirstLaunch
• Clean Build Folder in Xcode-beta
• Verified Command Line Tools setting points to Xcode-beta
⸻
❓Looking for guidance on:
• Whether this is a known bug in Xcode-beta
• If SwiftShims/PCM conflicts are expected between versions
• Best practices to safely migrate from Xcode stable to beta for Swift-based projects
Any advice is much appreciated.
Thanks,
Mathéo
Hi all,
I’m running into a persistent build issue with my Swift project ORSOFINAL after migrating from Xcode stable to Xcode-beta.app 26 (June 2025 version).
⸻
💥 Errors displayed:
1. C99 was enabled in PCH file but is currently disabled
2.
module file .../ModuleCache.noindex/SwiftShims-AXUM98L131W4...pcm
cannot be loaded due to a configuration mismatch with the current compilation
3. missing required module 'SwiftShims'
⸻
🛠 What I’ve already tried:
• xcode-select -s /Applications/Xcode-beta.app/Contents/Developer
• Deleted ~/Library/Developer/Xcode/DerivedData, ModuleCache.noindex, Archives, and Products
• Ran sudo xcodebuild -runFirstLaunch
• Clean Build Folder in Xcode-beta
• Verified Command Line Tools setting points to Xcode-beta
⸻
❓Looking for guidance on:
• Whether this is a known bug in Xcode-beta
• If SwiftShims/PCM conflicts are expected between versions
• Best practices to safely migrate from Xcode stable to beta for Swift-based projects
Any advice is much appreciated.
Thanks,
Mathéo
I found that the aggregated device correctly obtains input channels in the standard microphone mode. However, in voice isolation mode, it only retrieves channels from the first sub-device in the aggregated device's list. If I want to properly obtain channel information in voice isolation mode, how should I do it?
Just testing an existing app with Xcode 26.
I notice that content of UIBarButtonItem (either text or image) disappears when tapped (and reappear on release).
Those are custom, bordered buttons.
Attribute inspector:
Buttons in Xcode:
When selected in Xcode, we see a rectangle inside the rounder rect of iOS 26
In simulator:
When tapped in simulator:
I have edited code from
backButton.setTitleTextAttributes([
.font : boldFont,
.foregroundColor : UIColor.systemBlue,
], for: .normal)
to
backButton.setTitleTextAttributes([
.font : boldFont,
.foregroundColor : UIColor.systemBlue,
], for: [.normal, .focused, .selected, .highlighted])
to no avail.
What am I missing ?