I'm able to build, launch, and debug my Swift app on an iPad from XCode, with a scheme that uses the Debug configuration. If I edit the scheme to use the Release configuration, the build is different, as expected, because in the console it then says my app "was compiled with optimization - stepping may behave oddly; variables may not be available." Fine.
What I don't understand is why regardless of which configuration is in use in the scheme, code inside of #if DEBUG blocks is never executed, e.g.
#if DEBUG
print("This never gets printed")
#else
print("this always executes instead")
#endif
That's despite the fact that in my project settings, under Apple Clang - Preprocessing/Preprocessor Macros, it shows 1=DEBUG on the Debug line (and not on the Release line, as expected).
Why then does Swift behave as if DEBUG is never defined, regardless of the scheme's configuration? And what do I need to do in order to have debug-only code controlled by
#if DEBUG
blocks? Is there a Swift-lang setting I'm missing?
P.S. I know that #if/#else/#endif is an anti-pattern, but even Apple says to use it, e.g. in this presentation from WWDC 2020, at 16:29:
Introducing StoreKit Testing in Xcode - https://developer.apple.com/videos/play/wwdc2020/10659/
P.P.S #ifdef DEBUG works no better than #if DEBUG
Post
Replies
Boosts
Views
Activity
I have been trying to use StoreKit testing within XCode, but find that the original_purchase_date
field of the receipts it generates is missing or empty. That makes it unusable for testing non-consumable one-time free trials, for which that field provides the start date of the trial (regardless of how many times that purchase is later made or restored).
Am I missing something, or is this a known issue?
That field is always present in sandbox-generated receipts, and is one of the fields documented - https://developer.apple.com/library/archive/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html and approved for use outside of Apple.
In a SwiftUI app for MacOS, vertical sliders that I'd created using a rotationEffect of 90° disappeared when I upgraded to Sonoma 14.5 (23F79). With rotations less than 90°, the slider is still visible, but its button is enlarged, growing in size as the rotation angle approaches 90°.
Note that the sliders still work, even when rotated by 90° and invisible!
The screenshot and code below demonstrates the problem, which did not exist in MacOS 14.2.1
struct ContentView: View {
@State var speed = CGFloat(1)
var body: some View {
HStack {
let angle: [Double] = [0, 45, 80, 85, 90]
ZStack {
ForEach(0...4, id: \.self) { i in
ZStack () {
Rectangle()
Slider(value: $speed,
in: 0...10
)
}
.frame(width: 100, height: 10)
.rotationEffect(.degrees(angle[i]))
.offset(x: CGFloat(i * 100) - 180)
}
}
}
.padding()
.frame(width: 600, height: 200)
}
}
#Preview {
ContentView()
}