StateObject
In the past, StateObject was only available in ios 14, but all of a sudden I can use it in ios 13.
However, I can't find anywhere that StateObject is available in ios 13. Even when I go to its definition, it says ios 14.
I am using xcode 13.2
This appears to now be fixed in Xcode 14.3 Beta 1. When adding @StateObject a compilation error now occurs and a warning is displayed in Xcode stating:
'StateObject' is only available in iOS 14.0 or newer.
Add @available attribute to enclosing struct

I have checked to see if this is still occurring on Xcode 14 Beta 3 and unfortunately it is.
I have updated my feedback to Apple stating this.
Apple replied to my feedback that I submitted for this issue, asking if it still occurs while using Xcode 14 Beta 2, the unfortunate answer is yes. The issue is still occurring.
I have updated my feedback with the additional information they requested and hopefully they will be able to fix the lack of error produced when using StateObject in an iOS 13 project.
I think that this is a bug in the compiler.
Taking a very simple example application:
class ViewModel: ObservableObject {
init() {}
}
struct ContentView: View {
@StateObject var viewModel = ViewModel()
var body: some View {
Text("Hello, World!")
}
}
With the Targets Deployment target set to 13.0

and the Projects Deployment target also set to 13.0

If I build for an iPhone 13 on iOS 15 the application compiles and builds without a warning, and runs without issue.
However, if I build for an iPhone 6S on iOS 13 the application compiles and builds without a warning but when it runs it produces the following error:
dyld: lazy symbol binding failed: Symbol not found: _$s7SwiftUI11StateObjectV12wrappedValueACyxGxyXA_tcfC
Referenced from: /Users/andrew/Library/Developer/CoreSimulator/Devices/F12BA8CD-671F-4EA2-94E4-784DA2EE1A1C/data/Containers/Bundle/Application/0A6FA610-FF19-47EB-A062-4AA7A296F464/Thirteen.app/Thirteen
Expected in: /System/Library/Frameworks/SwiftUI.framework/SwiftUI
dyld: Symbol not found: _$s7SwiftUI11StateObjectV12wrappedValueACyxGxyXA_tcfC
Referenced from: /Users/andrew/Library/Developer/CoreSimulator/Devices/F12BA8CD-671F-4EA2-94E4-784DA2EE1A1C/data/Containers/Bundle/Application/0A6FA610-FF19-47EB-A062-4AA7A296F464/Thirteen.app/Thirteen
Expected in: /System/Library/Frameworks/SwiftUI.framework/SwiftUI
CoreSimulator 783.5 - Device: iPhone 6s (F12BA8CD-671F-4EA2-94E4-784DA2EE1A1C) - Runtime: iOS 13.0 (17A577) - DeviceType: iPhone 6s
And highlights the problem in Xcode

I would expect that the application should not compile and build if it is using an API that is only available for a newer SDK.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With