Thomas Kilian Thomas Kilian - 1 month ago 18
Swift Question

Create Swift framework (revisited)

I have read Create and import swift framework (and many more) but it does not work. Here's what I did: I created a vanilla framework and added a simple Test.swift.

enter image description here

This builds with no issues and I guess that this should be a valid framework containing my Test class.

Now I import this framework to another vanilla app:

enter image description here

But trying to access my framework fails:

enter image description here

mz2 mz2
Answer

With the information available from your question, "no such module" can mean that you either aren't linking against the framework, or the framework is not in the framework search path. Further, it looks like you have dragged the built framework directly into the dependent project, because I don't see the project where FW.framework included either as a top-level project in a workspace, or as a project dependency (i.e. you have not dragged FW.xcodeproj into the project navigator when you have FrameworkUse open). There are a few ways to resolve this:

  1. Drag FW.xcodeproj into the project navigator somewhere under the FrameworkUse project (this will add FW.xcodeproj as a subproject to the FrameworkUse project). Then go to build settings and a) add the FW.framework target as a target dependency to the FrameworkUse target, b) add the framework (from the Products group under FW.xcodeproj) as an embedded binary.
  2. Drag FW.xcodeproj to the top level in the project navigator when you have FrameworkUse project open. Xcode will ask if you want to create a new workspace (unless you already had a workspace open, at which case FW.xcodeproj will be added to the workspace). Similarly as with the above option, go to build settings and a) add the FW.framework target as a target dependency to the FrameworkUse target, b) add the framework (from the Products group under FW.xcodeproj) as an embedded binary.
  3. If you really want to depend on the built FW.framework instead of expressing a build dependency to it with either option 1 or 2, you need to a) add the framework as an embedded binary, and b) go to Build Settings and add the directory containing the FW.framework (whose location you can find by opening it in Finder into "Framework search path", for instance "$(PROJECT_DIR)/Frameworks" if Frameworks under the project directory is where you place built frameworks).
Comments