Swift Compiler Error (Xcode) while taking ios build - ios

I updated xcode to version 14. while i'm taking ios build shows error in xcode build
Swift Compiler Error (Xcode): Stored properties cannot be marked potentially unavailable with '#available'
error shows here in DKImagePickerController.swift file
#available(iOS 13.0, *) #objc lazy public var shouldDismissViaUserAction = false

Related

linking error trying to use SwiftUI - Undefined symbol: _swift_getOpaqueTypeConformance

I'm trying to add some SwiftUI, conditionally on devices (running iOS 13) that support it, as the deployment target for my iOS app is iOS 12.0. I'm using Xcode 11.3.1.
My code that conditionally presents a SwiftUI view (embedded in a UIHostingController) is wrapped in if #available(iOS 13.0, *) {, and my SwiftUI view is prefixed with #available(iOS 13.0, *).
As the name of the undefined symbol (_swift_getOpaqueTypeConformance) suggests, the problem is related to declaring the my SwiftUI body return type as some View - and I get this linking error with the default "Hello World" code Xcode generates when I create a new SwiftUI file.
However, if I change my SwiftUI view to not take advantage of opaque declarations and change my body type to var body: Text, the view builds and runs as expected.
I would seem to be building with incompatible Swift versions; but the version I think I need for opaque return types is Swift 5.1. I believe Xcode 11.3.1 provides Swift 5.1.3, and in fact I confirmed that from the command line via swift --version. In my project settings, I have Swift Language Version = Swift 5.
Any idea what could make the linker unable to locate this symbol?

SwiftUI - “Use of undeclared type xxx” on deployment targets below or equal to iOS 10

When archiving/building the app which uses SwiftUI for platforms <= iOS 10, the compiler throws errors "Use of undeclared type".
This happens even if the enclosing type is marked as #available(iOS 13.0, *) and also using #if canImport(SwiftUI).
SwiftUI framework is also weakly linked.
Everything works fine if you are running(debug) on an iOS 11+ device, or archiving for a target with minimum supported version <= iOS 11.
This failure occurs because builds with a deployment target earlier than iOS 11 will also build for the armv7 architecture, and there is no armv7 swiftmodule for SwiftUI in the iOS SDK because the OS version in which it was first introduced (iOS 13) does not support armv7 anymore.
I have managed to solve the archiving issue by wrapping the SwiftUI Code/Files in the preprocessor of #if arch(arm64).
Example -
#if arch(arm64)
#available(iOS 13.0, *)
struct MyCustomView: View {
var myStrings: [String]
var body: some View {
List {
ForEach(myStrings) { str in
Text(str)
}
}
}
}
#endif
This does disable previews in cases if your deployment target is <= iOS 10.
But if used only when archiving, this does work.
If anyone knows of a better solution. Please share.
Adding this answer so that someone in my situation can atleast make it work with SwiftUI.
Cheers!

transferCurrentComplicationUserInfo is unavailable for WCSession?

This is as straightforward as is sounds; when I try to use session.transferCurrentComplicationUserInfo(_:), I get the error message written in the title, word for word.
Looking at the documentation (transferCurrentComplicationUserInfo, WCSession) there's no indication that it's been deprecated... plus, if something is deprecated it says so in the error message and will still show up in Xcode's intellisense (albeight with strikethrough). For me, neither is happening.
So why Xcode saying it's unavailable?
This is my barebones code that causes the error message:
let userInfo: [String:Any] = [:]
let _ = session?.transferCurrentComplicationUserInfo(userInfo)
For some background, I'm using Xcode 10.1 and Swift 4.2. My app's deployment target is iOS 9.3 and my watch extension's is watchOS 4.0.
Probably, you are trying to call it from the Watch Extension, where it appears as unavailable.
The function transferCurrentComplicationUserInfo can only be called from the iOS app.

upgrading to XCode 8 broke my ability to build on my iOS 6 device?

I recently upgraded to XCode 8, and found that I can no longer build on my iPhone5 with iOS 6... Fortunately I kept around XCode 7, but apparently since I installed XCode 8, I somehow lost some linking for a dispatch queue symbol? When I try to run my app with XCode 7 on iOS 6, I now get an immediate crash:
dyld: lazy symbol binding failed: Symbol not found: _dispatch_queue_attr_make_with_qos_class
Referenced from: /var/mobile/Applications/0FE3B5A4-00AA-46F3-80A7-8EA45C64BEAE/myapp.app/myapp
Expected in: /usr/lib/libSystem.B.dylib
How can I resolve this?
Read the documentation for dispatch_queue_attr_make_with_qos_class. Note when it was added - iOS 8. You have to guard against the use of that function when run under iOS 7 or 6.
As documented in the SDK Compatibility Guide, you can do this:
if (dispatch_queue_attr_make_with_qos_class != NULL) {
// use dispatch_queue_attr_make_with_qos_class as needed
} else {
// The function doesn't exist for this device, do something else
}

Warning: unnecessary check for minimum deployment target

I have a Swift class which is linked against several targets with different deployment targets, the main project has iOS 7 minimum requirement and there is an extension with iOS 8 target.
Now when I compile project, the compiler throws warning on this line of code:
if #available(iOS 8.0, *) { ... }
"Unnecessary check for 'iOSApplicationExtension'; minimum deployment target ensures guard will always be true"
I have checked build settings options and found no switch to kill swift warnings.
I tried to define iOSApplicationExtension version target separately by this line but without success:
if #available(iOS 8.0, iOSApplicationExtension 8.0, *) { ... }
Is there any way to suppress this annoying message?
Found an ugly workaround to silence warning, but I hope there is a better way:
In iOS 8+ targets build settings, I defined a precompile flag in Build Settings -> Swift Compiler - Custom Flags -> Other Swift Flags:
-D iOS8target
Then I changed code to this way:
#if iOS8target
// iOS 8+ compatible code
#else
if #available(iOS 8.0, *) {
// repeat iOS 8+ compatible code again!
} else {
// iOS 7 code
}
#endif
It's not refactored and ugly, but it works!
UPDATE:
There is a swift compiler switch -suppress-warnings to omit all warnings. But it also suppress useful warnings.
Also if there is only one specific file which emits warnings, you can use -w flag in Building Phases pane. It will also suppress useful warnings but limited to one file.
The next release of Cocoapod (after 0.39.0) should have this issue addressed. Check this for more details.
Please check your deployment target into your General and set from 9.0
to 7.0 or less. this warning will remove automatically.

Resources