How to use Swift App + (Swift Framework + Objectiv

2019-03-30 10:52发布

What I am trying to do:

  • Create a swift dynamic framework - Say SwiftDemo.framework
  • Swift.framework depends upon an external Objective-C static framework (No source code available) - Say ObjCDemo.framework. This framework has it's module file and placed inside ObjCDemo.framework/Modules/module.modulemap
  • Put this SwiftDemo.framework inside an Swift application. Ideally I would want my swift app to be able to use both SwiftDemo.framework and ObjCDemo.framework without any error or warning.

What I have tried:

  • Create a swift dynamic framework SwiftDemo.framework

  • Added ObjCDemo.framework in "Linked Frameworks and Libraries". Put ObjCDemo.frameworks path in "Framework Search Paths" if not added automatically. Access ObjCDemo.framework using "import ObjCDemo". Build the SwiftDemo.framework. It builds fine, No error, No warning

  • Create a SwiftDemo application.

  • Add SwiftDemo.framework in "Embedded Binaries" section.

Try to build SwiftDemo.app, below is the error:

ld: framework not found ObjCDemo for architecture x86_64

Obviously SwiftDemo.app not able to find the ObjCDemo.framework which is used by SwiftDemo.framework, So next I did:

  • Added ObjCDemo.framework in "Linked Frameworks and Libraries" and accordingly set the "Frameworks Search Paths" of SwiftDemo.app target

Try to build SwiftDemo.app, No error but this is the console warning I get for every file in ObjCDemo.framework:

objc[15127]: Class is implemented in both /Users/tarun/Library/Developer/CoreSimulator/Devices/4391A259-64DF-4893-BE09-31B5D2D5BC8C/data/Containers/Bundle/Application/CD896A7B-1868-44D1-BFEA-6CC081AD41DB/SwiftDemo.app/Frameworks/SwiftDemo.framework/Swift and /Users/tarun/Library/Developer/CoreSimulator/Devices/4391A259-64DF-4893-BE09-31B5D2D5BC8C/data/Containers/Bundle/Application/CD896A7B-1868-44D1-BFEA-6CC081AD41DB/SwiftDemo.app/SwiftDemo. One of the two will be used. Which one is undefined.

Obviously these files are duplicated in both SwiftDemo.framework and SwiftDemo.app, So to avoid next I did:

  • Remove ObjCDemo.framework form "Linked Frameworks and Libraries" of SwiftDemo.app target but keep "Frameworks Search Paths" still pointing to ObjCDemo.framework path.

Try to build SwiftDemo.app, No error but this is the compile time warning:

ld: warning: Auto-Linking supplied '.../SwiftDemo/ObjCDemo.framework/ObjCDemo', framework linker option at ..../SwiftDemo/ObjCDemo.framework/ObjCDemo is not a dylib

No matter what I just couldn't get pass these errors or warnings. Anyone got any solution to this?

0条回答
登录 后发表回答