1

I'm writing a Cocoa Touch Static Library in Objective-C. It will be distributed through Cocoapods and the developers using it should also be able to do this in Swift. In my test projects the library can be used perfectly in Objective-C, but in Swift I get the compiler error: No such module MyLibrary.

In the Library Target Defines Module is set to YES. According to the Apple guide here, that's the only thing one must do: https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html

melbic
  • 11,988
  • 5
  • 33
  • 37

1 Answers1

0

To implement pch file in existing swift project:

File > New > File... (macOS app for your case)

add pch file

then you can import your Objective-C library like this in your pch file (test.pch is my file)

#ifndef test_pch
#define test_pch

#import <YourLib/YourLibMainClass.h>

// Include any system framework and library headers here that should be included in all compilation units.
// You will also need to set the Prefix Header build setting of one or more of your targets to reference this file.

#endif /* test_pch */

Now you need to tell your project there is a pch file. Go to your target build setting and make a search for "Prefix Header".

At Apple LLVM 8.0 - Language section add value for Prefix header key (be careful with your pch file project path)

enter image description here

You will could import your library on a swift file

import YouLibrary
guiltance
  • 236
  • 1
  • 8
  • 1
    Ok, now I understand what you mean, but that wasn't my question. I'm writing a framework. I don't want to tell everybody who is using it to create a .pch File. – melbic Dec 15 '16 at 16:37
  • @melbic - http://stackoverflow.com/questions/32459678/how-to-mix-swift-and-objective-c-in-a-pod-lib – johndpope May 11 '17 at 18:07