Objective-C package can't find header file

We are trying to support SPM in our pure Objective-C SDK (framework target in Xcode) but when it is included in a project, Xcode can't find an internal header file. I created a test project: https://github.com/rabc/spm_objc_test

When it is included in the project using Xcode SPM management, the build gives the error 'MyPrivateClass.h' file not found that is imported in MyPublicClass.h (the error is the same when it is imported in *m file). I tried using cSettings(it is in another branch in the same repo), but no luck.

What am I missing?

I made it work without altering your directory structure by changing the following:

diff --git a/MyTest/MyPublicClass.h b/MyTest/MyPublicClass.h
index 09a33ba..4a82b63 100644
--- a/MyTest/MyPublicClass.h
+++ b/MyTest/MyPublicClass.h
@@ -7,7 +7,11 @@
 #import <Foundation/Foundation.h>
+#import "Internals/MyPrivateClass.h"
 #import "MyPrivateClass.h"
diff --git a/MyTestSDK/MyTestSDK.h b/MyTestSDK/MyTestSDK.h
index 19de043..462c8c5 100644
--- a/MyTestSDK/MyTestSDK.h
+++ b/MyTestSDK/MyTestSDK.h
@@ -16,5 +16,8 @@ FOUNDATION_EXPORT const unsigned char MyTestSDKVersionString[];
 // In this header, you should import all the public headers of your framework using statements like #import <MyTestSDK/PublicHeader.h>
+#import "../MyTest/MyPublicClass.h"
 #import <MyTestSDK/MyPublicClass.h>
diff --git a/Package.swift b/Package.swift
index 49141eb..a226201 100644
--- a/Package.swift
+++ b/Package.swift
@@ -10,6 +10,12 @@ let package = Package(
         .library(name: "MyTestSDK",  targets: ["Core"])
     targets: [
-        .target(name: "Core", path: "MyTest", publicHeadersPath: "MyTestSDK")
+        .target(name: "Core", path: "", sources: ["MyTest"], publicHeadersPath: "MyTestSDK"),
+        .target(
+          name: "SampleClient",
+          dependencies: ["Core"],
+          path: "SampleClient",
+          cSettings: [.define("SWIFT_PACKAGE")]
+        )
diff --git a/SampleClient/main.swift b/SampleClient/main.swift
new file mode 100644
index 0000000..512b47b
--- /dev/null
+++ b/SampleClient/main.swift
@@ -0,0 +1,3 @@
+import Core

However, unless you have a very good reason not to, it will probably be more convenient to rearrange the files so that SwiftPM and any other build systems you need to support can use the same import paths without any #ifdef statements.

Woah, indeed now it works. Thanks!

Indeed, it is not convenient at all. I will see what we are going to do. Thanks for the help!

Terms of Service

Privacy Policy

Cookie Policy