I have an existing Xcode project that contains targets for a "traditional" iOS app ("Foo") and an iOS framework ("FooLib"). When the Xcode 12 beta dropped a few days ago, I added a multiplatform (iOS/macOS) SwiftUI app target ("Foo SwiftUI") to the same project. Now I want to make my framework cross-platform, too, so I added a multiplatform Swift Package ("Foo Package") to the project and moved the iOS framework classes to the new Swift package. I then added this package to all app targets' Frameworks, Libraries, and Embedded Content sections. It appeared to work for all app targets until I cleaned the project and tried again. Now the app targets complain that the Foo Package can't be resolved:
Missing package project 'FooLib'.
I tried removing & re-adding the FooLib package to the app targets, but it no longer shows up in the pop-up list of frameworks and libraries to add. Are local Swift packages explicitly unsupported in Xcode projects? Do I need to put the package in its own Git repo and set it up like any other third-party package dependency?
What I'm most confused about it that it looks like it worked right after I created the Swift package, but not after I cleaned the project and tried re-running the app targets.
OK, sorry for my previous answer. — It is obvious how to share a package with yourself by way of a remote URL, such as GitHub, that serves it. Basically you are playing the role of both developer and end-user, and it's clear how to do that. So I think what's needed here is a step-by-step tutorial to sharing a package with yourself locally without actually serving it.
In Xcode, choose File > New > Swift Package and save as MyLibrary to the Desktop.
Now choose File > New > Project, choose the iOS App template, and save as App1 to the Desktop.
You now have two windows open. Drag MyLibrary from the project navigator in the MyLibrary window into the empty area at the bottom of the project navigator in the App1 window.
Quit Xcode.
Launch Xcode again and open App1. Look, the MyLibrary icon now has hierarchical contents. Edit the app target and add MyLibrary library as a dependency.
You can now edit MyLibrary; you can also import MyLibrary in your code and you will be able to use any public members of public types.
Close App1 and create another project, App2. Repeat steps 3, 4, 5, and 6.
From now on, either App1 and App2 can "see" MyLibrary. From either one, you can edit MyLibrary, you can import it and use its code. But you cannot have both App1 and App2 open at the same time. If you do, one of them will complain that the package is missing. So you'll be fine as long as you only have one at a time open.
Now, if you want to escape that limitation, then go back to the first way of dealing with all this: upload the package to GitHub and acquire it in your projects as a package dependency.
For me, it works using Xcode Workspaces “around” local Projects and Swift Packages.
Create App project
Create Swift Package
Create Workspace for app project
Add the App project to the Workspace
Add the Swift Package to the Workspace, too
In the app target “General” settings, “embed&sign” the Swift Package from the current workspace
You might have to restart Xcode afterwards for it to pick up on the changes ...
Related
The goal is to import a local Swift Package "Shared" into a Xcode project and have them both in a workspace.
I have created a workspace, dragged and dropped both the package and the project in, and then added the package to the app by adding it to Frameworks, Libraries, and Embedded Content.
This works when building from the workspace! But I have to make it also possible to build from the app project, currently it throws: "Missing package product 'Shared'".
I know it is possible to do what I want because I have an example project where it works, in there Shared is listed as a local Swift Package in the app project, in mine it is not. In the project Shared is listed under Frameworks, Libraries, and Embedded Content but can't be added again after removing the reference.
It would be great if someone could help me with this!
The solution is to create a local Swift Package in the app project and to import the Shared Package there. Then it will be available in the whole project.
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
I downloaded SwiffCore (https://github.com/musictheory/SwiffCore) for iOS and the Demo project contains a the main SwiffCore xcode project inside with all the necessary libraries.
Now I want to use SwiffCore in my project.
How do I import the xcode project inside my project?
I tried by dragging inside but it does not copy all files.
I have seen it a lot in other xcode samples.
Regards
mirza
From what I see on the github repository, you just need to drag the Source folder into your project and then use the classes as indicated by the documentation.
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.
I'm working with an open source library that's made available as a git repository (XML-RPC) and I'd like to use it in an iPad application. As I understand it, iOS applications should use static libraries for their linking.
Since this comes as a dynamic library, how can I convert it to something I can link with my app and use?
Maybe naive answer but why not just add all the relevent files in the repository to your app and just build it?
Put the files in a seperate folder obviously so you can update them to a newer version if you need to etc. Lots of projects I've done have an 'external' folder that just contains codethat I use from 3rd party sources. I've usually got the source so just compile it into my app and don't bother with making it a library.
Or are there tricky conditions that need to be met to compile this code?
I ended up doing this in several steps:
First, I opened the library project in Xcode and created a new target for the static library. I then made a directory in the project folder called "XMLRPC" and moved all the header files to it. I deleted the now-red invalid references to the header files, and re-added them (but kept the box for copying them to the current folder unchecked).
I added this Xcode project to my main project with a relative reference. I opened my main app's target and added the library project as a direct dependency, and checked the "Always search user paths" option on my main app's target settings.
Lastly, I modified the general Xcode preferences to use a shared build directory. I haven't tried it without that since it was something I wanted anyways; it might not be necessary.
My revision control has two folders in it: one's my project, and the other's the library. The library is still under git control within mercurial; I'm hoping this doesn't cause any issues.