Hello, We are attempting to use the swift-export ...
# swift-export
e
Hello, We are attempting to use the swift-export feature to directly connect our KMP module to our iOS app. We already have a working connection using the Cocoapods plugin. We encountered an issue when trying to use an Objective-C class within the
iosMain
source set of our KMP module. Specifically, we are trying to use
NSURLCredential
. I'm relatively new to KMP and might be making a mistake. This error is easy to reproduce. I downloaded the sample project from this repository and added a new class in `shared/src/iosMain/IOSSource.kt`:
Copy code
kotlin
import platform.Foundation.NSURLCredential

class ConnectionCredential(val credentialInfo: NSURLCredential)
I receive a large error message when trying to build the iOS app. Xcode complains that
NSURLCredential
has been obsolete since Swift 3. I'm unsure how to set up the correct version of Swift or how to properly import from Swift in the
iosMain
source set. Any guidance would be greatly appreciated. Thank you!
The error message
Copy code
/Users/esdras/git/exemplos/swift-export-sample/iosApp/  /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSURLCredential.h:42:12: 'NSURLCredential' was obsoleted in Swift 3

Using global toolchain override 'Xcode Default'. (in target 'SharedLibrary' from project 'Shared')

Using global toolchain override 'Xcode Default'. (in target 'KotlinRuntime' from project 'Shared')

Using global toolchain override 'Xcode Default'. (in target 'SharedBridge_SwiftExportSampleModuleB' from project 'Shared')

Using global toolchain override 'Xcode Default'. (in target 'SharedBridge_SwiftExportSampleModuleA' from project 'Shared')

Using global toolchain override 'Xcode Default'. (in target 'SharedBridge_Shared' from project 'Shared')

Using global toolchain override 'Xcode Default'. (in target 'SwiftExportSampleModuleB' from project 'Shared')

Using global toolchain override 'Xcode Default'. (in target 'SwiftExportSampleModuleA' from project 'Shared')

  

  

  --- xcodebuild: WARNING: Using the first of multiple matching destinations:

  { platform:iOS Simulator, arch:arm64, id:E6E63D0A-9E25-4A1D-AFB7-0552BFC98D89, OS:18.5, name:iPhone 16 }

  { platform:iOS Simulator, arch:x86_64, id:E6E63D0A-9E25-4A1D-AFB7-0552BFC98D89, OS:18.5, name:iPhone 16 }

  ** BUILD FAILED **

  The following build commands failed:

  	SwiftCompile normal arm64 /Users/esdras/git/exemplos/swift-export-sample/shared/build/SPMPackage/iosSimulatorArm64/Debug/Sources/Shared/Shared.swift (in target 'Shared' from project 'Shared')
I've tested using version 2.3.0-Beta1
a
Hi! Thanks for the report, that was a tricky one to be honest. Do you actually need
NSURLCredential
to be a part of your public API? Or is it an internal implementation detail that was accidentally leaked to public api surface?
KT-81934 Swift export should look up
SwiftBridge
and
SwiftName
when translating types from platform libraries Ticket for that issue
e
Thank you. I use NSURLCredential to setup the user certificate at ChallengeHandler. Example:
Copy code
actual class HttpClientEngineProvider(
    private val urlCredential: NSURLCredential?,
) {
    actual fun provideEngine(): HttpClientEngine =
        Darwin.create {
            urlCredential?.let {
                handleChallenge(MTLSChallengerHandler(urlCredential))
            }
        }
}
This ChallengerHandle was implemented by MTLSChallengerHandler. Both codes are inside of my iosMain
a
Yeah, for you
NSURLCredential
is a part of public API. I'm sorry, this is a bug on the side of swift export, that is more of a feature. We are researching possibilities, how to handle such case, but for now I can only suggest using objective-c export. And again, thanks for the report!
🙂 1