Hello,
Is it possible to use types defined in Swift packages in Obj-C code in Xcode 11?
This document: Importing Swift into Objective-C | Apple Developer Documentation (assuming that I understand it correctly) seems to imply that Xcode will auto-generate appropriate headers to allow the user to reference Swift types in Obj-C code.
I would like to use a Swift package in an Obj-C codebase that I have for an old macOS Cocoa application. In Xcode 11 it appears to be possible to add Swift packages to projects, even if they are Obj-C based.
The documentation linked above states:
You can work with types declared in Swift from within the Objective-C code in your project by importing an Xcode-generated header file. This file is an Objective-C header that declares the Swift interfaces in your target, and you can think of it as an umbrella header for your Swift code. You don’t need to do anything special to create the generated header—just import it to use its contents in your Objective-C code.
The header's name is generated from your product module name, followed by
"-Swift.h"
.
and
When you're building an app target, you can import your Swift code into any Objective-C
.m
file within that same target using this syntax and substituting the appropriate name:#import "ProductModuleName-Swift.h"
However, when I try to test this by using the sample Swift Library 'DeckOfCards' Xcode cannot find the generated header.
Am I being an idiot, or is this something that isn't intended to be supported in the Xcode / Obj-C / Swift / SPM interoperability?
Thanks.
(from DeckOfPlayingCards/Package.swift)
let package = Package(
name: "DeckOfPlayingCards",
products: [
.library(name: "DeckOfPlayingCards", targets: ["DeckOfPlayingCards"]),
],