Monday, 4 February 2019

Swift Usage in Objective-C inside Framework/Subproject

Assume you have a main project and a sub framework. Check How to add framework to main project'
Check example code at Github: https://github.com/Sylvia-YiyinShen/SwiftOCInFramework

Probably, you will get an error when using Swift in Objective-c:
Receiver for class message is a forward declaration

Solution:
  • Make Swift class/properties/functions exposed to Objective-C public
  • @objc added for class/properties/functions
  • Drag the Objective-C class(where Swift class is used) .h file to Headers section in Build Phases 
  • Import the Objective-C(where Swift class is used) .h file in Umbrella file in the framework
  • Import <PROJECTNAME/PROJECTNAME-Swift.h> in Objective-C class(where Swift class is used)

No comments:

Post a Comment