Add .framwork to a Swift Package? - swift

I have a Swift package I would like to make public, however I do not want the source code for all of the files shared.
My solution was to bundle the private source code into a .framework and have the swift package call the private source code.
However I cannot seem to be able to add the .framework into the Swift Package project. Any help?

There is an accepted proposal for binary dependencies in SwiftPM. So when that feature ships you will be able to zip up your framework, if it is an xcframework, and link against it. Until then you can only use unsafe linker flags to do so which means you can’t use the package with Xcode unless it is a local package.

Related

Xcode does not generate DYSM for SPM dependencies

Xcode is not generating dSYM files for my three SPM dependencies.
I have tried creating a new Swift only project and including a SPM package like CocoaLumberJack and even there I am not given a dSYM for release.
I am using Xcode 12.0.1, I have looked through all kinds of build settings with no luck to force them to be generated or find where Xcode puts them if it is generating them.
Swift packages by default are treated as static library, that is why you don't see the embed options for them in Frameworks, Libraries, and Embedded Content section:
Static libraries don't require separate dSYM files are they don't have any executable. They are directly contained in consuming app executable so the static library symbols will be available in application's dSYM file. If you inspect you app's ipa you won't find the swift package module in Frameworks directory.
You can also make your swift package exposed product dynamic library by specifying library type as .dynamic:
.library(
name: "SwiftLibrary",
type: .dynamic,
targets: ["SwiftLibrary"]
),
This will make your package module dynamic library and will allow you to choose embed option in XCode:
If you make your package module dynamic and you can inspect your ipa to see this embedded in the Frameworks folder. After making your package module dynamic you separate dSYM file will be generated for it.

How to add Carthage support to a SPM dependency?

I created one Swift Package Manager dependency and I need to add a Carthage support in order that depndency later to be used with Carthage in a project. Can someone explain the steps involved in doing this?
Adding Carthage support to a dependency that uses SPM should be the same as adding Carthage support to a dependency that doesn't use SPM. The presence of SPM support should not impact Carthage at all.
The Carthage README has steps for adding Carthage support to your package. To summarize:
Make sure your Xcode schemes are marked as Shared.
Make sure carthage build --no-skip-current successfully builds your dependency.
Make sure to tag your releases with git tags.
OPTIONAL: prebuild binaries of your framework for quicker installation
The thing is a SPM package doesn't need a xcworkspace file. See e.g. one of my framworks for example. In that case using it as carthage dependency is not that straightforward or even possible.
The second thing to consider is that Apple changed the way resources, bundled with a framework are located from the app hosting the framework:
Important
Always use Bundle.module when you access resources. A package shouldn’t make assumptions about the exact location of a resource.
The main pain point here is that this struct is generated when SPM builds the framework but is not created when Carthage builds it. Read detailled information here.
If both points above don't aplpy for your framework then moshe-katz is right and you can just follow the proposed setup instructions. Otherwise please tell me how that works. I already search a solution to this problem for quite some time.

swift package manager link dynamic lib

i used swift on linux, made the Package.swift file including some libraries, but when i built the project with swift build command, the libraries were static linked with the executable file. i tried to generated a Xcode project used the swift package generate-xcodeproj command, built the project in Xcode, then opened the Product directory, i found that the libraries were dynamic linked with the executable file, what did the Xcode doing? and how can i build it as a dynamic link use swift build command, could you help me😔😔
SwiftPM version 3 was only able to build executables with statically linked libraries. In SwiftPM version 4 (currently in beta, will be released this fall) you can also build with dynamically linked libraries. See SE-0146 for more information.

how to add .bundle file to a nativescript plugin

I have some thirdparty code I want to add to my nativescript (iOS) project. The code consists of a .framework file and a .bundle file which contains a .momd file. I was thinking of adding this via a custom plugin, the docs are pretty clear on how to add the .framework file, but am not sure how I add and reference the bundle and underlying .momd file. Does anyone have any experience of this that they can share please?
I spent a lot of time poring over the iOS interop documentation while working on my nativescript-midi plugin, but I don't recall seeing anything specifically on adding bundles or .momd files. If possible, I suggest you create a new "container" iOS framework project in which you can import your desired framework, bundle, and .momd file, and then import that combined framework project into your plugin via a Podfile. That's essentially the approach I took to import a C library in my project (the cocoa-midi-message-parser repo referenced by the Podfile in my plugin).
In case anyone else needs to do this. I ended up using cocoapods xcodeproj gem to inject my file into my workspace file. A gist of the working code is here.

Open Source for non-ARC (Automatic Reference Counting) and ARC Users

We have some open source libraries that are distributed via code into other projects via git modules with Xcode. Some of the projects would remain with explicit retains/release while other projects would like to leverage Automatic Reference Counting. Is there anyway for the same source to be compilable in Xcode projects with and without ARC? Would it work if it was compiled into a static library?
If you bundle a project that compiles your open source library as a static library, and the other projects link against your static library instead of compiling the source directly, then that would work. The other projects can embed your library's project file if they want, so that your library will get compiled before theirs, or you can just distribute the static library pre-compiled.