Create Swift framework (revisited) - swift

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.
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:
But trying to access my framework fails:

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:
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.
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.
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).

Related

UI Test target does not recognize Swift package from custom framework in xcworkspace

I am developing several projects in a single workspace (monorepo). The workspace contains a shared framework that contains code shared between the projects. Some of the code depends on external packages that I import using the Swift Package Manager. Everything is working except that the packages aren't recognized when I use the UI testing target. When I run the UI tests for one of the projects it complains that the packages cannot be found (in the framework). Another solution that suits my needs is also welcome. Anyway, I'm using Xcode 11.3. To reproduce:
Create a new workspace.
Add a new project A and a new framework B into the workspace.
Add any dependency (for example SDWebImage) to the framework.
Add a Swift-file to the framework that just does import SDWebImage.
Now add framework B as a dependency to project A.
If you build project A or unit test project A, there is no problem. However, when you run UI tests on project A it complains that it cannot find the module SDWebImage in the Swift-file you added in point 4 above. Any idea how to solve this?
Edit: When I use Cocoapods instead it gives me the same error. When I use use_frameworks! it doesn't give me the error, but it crashes with "SDWebImage: image not found".
You have to manually add your B framework as a linked library in on your UI Tests target under Build Phases -> Link Binary With Libraries

Eclipse link web projects java build path

In Eclipse have a java web project and I want to link it to another java project. Saying that:
Project A: Web project
Project B: Another java project
Normally can you achieve it by going to the properties of project A -> Java build path -> Projects and add the project B.
However if project A is a web project running inside tomcat then at runtime I receive a ClassNotFoundException for the classes of project B.
One solution to to problem is to export project B as a jar file and use it inside project A (put it in the WEB-INF/lib directory).
However this is not the case because I want also to debug at the same time project A AND project B
Go to Project A's Deployment Assembly property page and add Project B as a project Directive Type.
Eventually I found one good solution.
In eclipse from the properties of project A go: Java Build Path -> Source -> Link Source
in the "linked folder location" give the src folder of project B and in "Folder name" just put "src2" (just something different from "src").
This way eclipse creates a symbolic folder src2 which links classes of project B to the space of project A.
After that everything works fine:
You can compile and run project A without any ClassNotFound Exception.
You can debug classes from both Project A and project B at runtime.
Classes from project B are kept in a separate folder in the filesystem totally independent (this is also useful when you use a source control system like SVN, because two projects continue to be independent). Notice that even folder "src2" is not a real one, so no change in project A.

what's wrong with this approach re referencing another project in Xcode 4?

I'm trying to reference another Xcode4 project within Xcode4 but having troubles - what's I'm currently doing is as follows:
In project B in XCode4 I drag in project A (from Finder) into project B
In project B's main target, in Build Phases / Target Dependencies I add/select my project A's main target.
I put an, #import "myProjectAClass", in one of my project B files
when I compile I can an ERROR "myProjectAClass no such file or directory"
Any suggestions? What is the minimum number of places I need to touch/adjust in XCode4 project configuration such that I can start using clases from project B in project A, and it will all compile?
If I'm reading this correctly I had the same issue the other night. Except that I was dealing with two targets, one that built a static library and the other that ran an app to executes tests on the static lib. Here's what I did
Target A builds a static lib.
Target B runs a unit testing suite for testing target A's static lib.
In target B's settings:
Add Target A as a dependency. This ensures that it is built first. (I think :) )
Add the static library (libA.a) from Target A to Target B's Link Binary With Libraries list along with any frameworks the lib needs.
The second item is the important one. Adding a dependency (as I understand it) doesn't automatically include any of Target A's output to Target B's linking phase.

Xcode4 project with custom configuration name vs dependency library Debug/Release?

I have an Xcode app project with available configurations "Foo", "Bar", and "Baz". This project is dependent on a static library with configurations "Debug" and "Release".
Xcode4 is building products from the app project into a "Foo-iphoneos" directory, and products from the library project into a "Release-iphoneos" directory.
What is the best practice for having these two projects share the same build products directory?
You can add the following path to library search paths for any non-standard configuration:
"$(BUILT_PRODUCTS_DIR)/../Release-$(PLATFORM_NAME)"
This works for me with xcode 4.6. I'm not sure if there is a way to control which configuration will get built for the dependent sibling projects, but for my purposes Release was what I wanted.
One solution is that if your dependent projects have the same configuration names as the main project (i.e. Foo, Bar, Baz), then Xcode will match them up and build using the same configuration.
So, if you wanted a debug build instead of a release build, you could duplicate the Debug configuration and call it Foo. If you do not really need both, you could rename the configuration instead of duplicating it, but with example names like Foo, I am not sure what would make sense for your situation.
However, the title mentions Xcode 4. The technique described above is what I used to do in Xcode 3; I haven't figured out how to manage these configurations yet in Xcode 4. I'm trying to figure that out now.
Update: To manage configurations in Xcode 4, you can click on the name of your project or dependent project towards the top of the project navigator (where all your files/folders are listed on the left side). In the main window, select Info (the other tab is Build Settings). You will then see the Configuration section where you can add/delete/rename your configurations.
I have found that if your target and dependencies' configurations don't match then the dependencies will be built with the Release configuration.
I couldn't find a way to customize that.

Libxml in a library for ios

I have created a cocoa touch static library that contains functionality that I want to include in several apps. This library is linked to libxml and I have the header search path /usr/include/libxml2. The library builds correctly.
I include this library in another xcode project as a reference (by dragging the library xcodeproj file into my app xcode project. I also setup the target to have the library as a direct dependency, setup the header search path to include /usr/include/libxml2, and add libxml2.dylib in the frameworks.
The problem is, when I try to build the project is has a build error:
Libxml/tree.h: No such file or directory.
I initially had this problem trying to build the library and solved it by adding the header search path and framework into the project for libxml2.
Incidentally, i have another app that uses the library but does not use libxml, it builds and runs correctly.
So the problem seems to be using libxml in both the app and a linked library.
Anybody any ideas?
Yours hopefully,
Neil.
You probably need to add the include path /usr/include/libxml2 to both the target and the project.
To add it to the target, right click on the target and select Get Info.
To add it to the project, go to the Project menu > Edit Project Settings.
In both cases, make sure you've selected Configuration: "All Configurations".