0

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

Community
  • 1
  • 1
qwerty_so
  • 35,448
  • 8
  • 62
  • 86

1 Answers1

1

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).
mz2
  • 4,672
  • 1
  • 27
  • 47
  • I wen't with 3. It's a bit crazy that Link with Binary" shows my framework, but actually one needs to add the search path in addition. Once you know it, it's easy. But basically this is not what I call user friendly. Thanks! – qwerty_so Oct 10 '16 at 15:51
  • Yep, it's burnt me many a time too. It's especially unhelpful that the error message does not change at all from adding the linking stage in this case. – mz2 Oct 10 '16 at 15:53
  • Additionally, you need to add the framework to General/Embedded Binaries or you get a "dyld: Library not loaded" error. – qwerty_so Oct 10 '16 at 16:09
  • Yep, I did include that in my answer. Another option is to create a "Copy phase" where you place the framework under Frameworks inside the binary (this is basically what the "Embedded binary" thing, that was introduced a few Xcode versions back, does). – mz2 Oct 12 '16 at 09:34