How to add Swift Package to DEBUG builds only? - ios

How to add a dependency that only needs when building with Debug configuration?
Or better yet, how to exclude a Swift Package from Release configuration?
I tried to use EXCLUDED_SOURCE_FILE_NAMES build settings, but package sources are not directly linked.

You can create a Framework for debug libraries, and exclude the actual framework file from Release builds. ✨
Add the Swift Package to the project
Create a framework called DebugPackages
Add the Swift Package to the framework at General/Frameworks and Libraries
Add DebugPackages.framework to the Build Options/Excluded Source File Names build setting in Release configuration.

Related

Bazel - Can't compile without import Foundation, UIkit,

I'm trying to compile a swift project with Bazel, version 4.2.1.
I have a main project with multiple CocoaPods submodules of my own installed. I have a WORKSPACE and a BUILD configuration file for the project and another WORKSPACE and BUILD for each submodule.
I add the secondary workspaces as local_repository in the main workspace. I create the submodule build with a swift_library and add it in the main build in deps.
If in a .swift file, located in the submodule, I create a variable "var dateIni: Date?" I get an error "error: cannot find type Date in scope". I can solve this with "import Foundation" but xcode doesn't need it, I would like to be able to compile in Bazel without having to do these SDK frameworks imports. Is there any way to solve this?
I can post code or explain it better if you need more information.

Build Libraries for Distribution” into ”Yes” Swift

In my project I have enabled the Build Libraries for Distribution” into ”Yes” into my SDK build setting, to prevent swift upgrades from causing a problem for third party libraries. In this case, When I Build with the project for SDK, I have set legacy mode but I am facing issue like below:


The legacy does not support Build Libraries for Distribution” into ”Yes”.
How to fix this? I can able to build the project new build system instead of legacy mode
The reason for setting legacy mode is When I set a new build system and prepare to build I am getting this below error. To fix this I am using legacy mode
Multiple commands produce '/Path/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/GoogleUtilities.framework':
1) Target 'GoogleUtilities-00567490' has create directory command with output '/Path//IntermediateBuildFilesPath/UninstalledProducts/iphoneos/GoogleUtilities.framework'
2) Target 'GoogleUtilities-54e75ca4' has create directory command with output '/Path//IntermediateBuildFilesPath/UninstalledProducts/iphoneos/GoogleUtilities.framework'
The workaround for this build system issue is to explicitly add all the needed GoogleUtilities subspecs to the Podfile. See the Podfile.lock file to get the list. Full details at https://github.com/firebase/firebase-ios-sdk/issues/4087

Xcode: Custom build configurations in Swift Package Manager

I'm trying to get SPM to work with different build configurations other than Debug and Release. Our iOS project has different schemes (e.g. Debug-Staging, Debug-Production, Alpha-Staging, Alpha-Production, etc.) where I set the bundle identifier, some flags, etc.
Is there a way to achieve that diversification even if SPM only "understands" Debug and Release?
Specify path to your custom config file when invoking generate-xcodeproj command.
Sample
swift-package generate-xcodeproj --xcconfig-overrides Config.xcconfig

Carthage build umbrella framework

We are developing a dynamic umbrella framework which consist of several other frameworks. Our framework structure is in below
Base.framework
SubFramework1
SubFramework2
SubFramework2.1
SubFramework2.2
SubFramework3
And our xcode project file for the umbrella framework(Base.framework) is structured like this.
But when I execute carthage build command , it finds some of the sub frameworks and doesnt able to find some of the sub frameworks.
What should I do in order to compile the framework as its structured in our xcode project
You can see our framework in the below link:
https://github.com/Kandy-IO/test-cp
(All the subframeworks are in SubFrameworks folder of CpaaSSDK.framework)
Make sure that all the sub frameworks are exposed to carthage build system by selecting them as shared schemes.
Shared schemes
As mentioned in carthage doc on github.
Share your Xcode schemes
Carthage will only build Xcode schemes that are shared from your
.xcodeproj. You can see if all of your intended schemes build
successfully by running carthage build --no-skip-current, then
checking the Carthage/Build folder.
If an important scheme is not built when you run that command, open
Xcode and make sure that the scheme is marked as Shared, so Carthage
can discover it.
Doc Link - https://github.com/Carthage/Carthage#share-your-xcode-schemes

iOS : How to generate a .framework file from a GitHub project

There is a Swift project on GitHub that I want to include in my iOS app.
In my iOS app, I use Carthage. But the GitHub project is not compatible with Carthage (only with Cocoapods), so I need to include the .framework file in my project manually.
How can I generate the .framework file without Carthage?
Building the framework is not always the same across projects. That being said, there should be a target available when you open the project to make the framework build. It should look something like this.
After clicking run the framework is usually output to the products directory.
If this doesn't work for you with this project then maybe you could share a link to the github page for the project and I could provide more instruction.
Fork Project
Change scheme to shared in scheme management (more information on Carthage docs)
Add your fork to your Cartfile
You can stop here but I highly recommend do this after:
Update README with information about Carthage support
Make a pull request

Resources