How to develop several Swift Package Manager packages in Xcode? - xcode

I am developing the main app and a library (open source, forked but will go back into main repository) used by the app at the same time. I want to use Swift Package Manager and Xcode at the same time. What is the best setup in order to use the best of both worlds? Can I develop both in one workspace?

I'll describe the approach I've used before. I'm assuming you have the Swift Package available as source code in a folder, e.g. cloned using Git.
Open your main app project
Drag the root folder of the Swift Package onto your Xcode project
Open the project overview, select your app target, and under "Frameworks, Libraries, and Embedded Content", add your library
Import the library in any Swift file where you depend on it
This will resolve and fetch all dependencies and still allow you to change source code in the library on the fly if you need to.

Related

Do I have to install gin framework in every new folder I create in visual Studio code for Golang programmes?

I have already installed gin framework in a different folder on my desktop named Gingo. I am learning how to build a web RESTful API through the Gin framework,
by starting the implementation of the backend code that is needed to support our Go Music.
But I have created another folder on my desktop for this Go Music named backend, so do I have to install gin framework in this folder as well?
The project can be found at https://github.com/gin-gonic/
gin.
i think you must install in every project, in my opinion because framework on golang just thrid party labrary. but if you want to install on your system you can try this. maybe its can be new journery on your programming
The way you use external libraries and frameworks in Go is by using Go modules. Initialise your project by running go mod init name-of-project in the backend folder (or whatever the root folder is for your Go code).
Now, if you want to add gin to your project, you can run go get github.com/gin-gonic/gin, which adds gin to the dependencies of your project (you can see all dependencies in the go.mod file in the project root).
The gin code will be downloaded and placed in the pkg folder in your GOPATH (often ~/go). This way the code has to be downloaded only once, and every time you import it it is simply using the already present code. You do have to add it to the dependencies of your project every time though.
For more information about Go modules: https://zetcode.com/golang/module/

Xcode: how to work with library/framework conveniently while keeping code private towards others?

I have been following this tutorial: https://medium.com/better-programming/create-swift-5-static-library-f1c7a1be3e45
However, it is inconvenient to copy the new .a file every time I make a change to the library. What is the common setup during development of the static library? Do a "copy to iOS project folder" in the build script or linking the frameworks "Products" folder in the iOS project etc.?
During development, Subprojects seem to be a really useful way (https://www.raywenderlich.com/2658-creating-a-static-library-in-ios-tutorial). However, copying the project to another computer renders it useless as it seems to rely on the Subproject and not e.g. cache the data from the last build.
The background is that I want to work with a client that I don't want to give access to my private API.
I am looking for a solution that lets me
work on the project as well as the library conveniently (either by submodules or by having opened 2 Xcode windows at the time)
commit changes to the Git repo (via the Xcode Source Control) and automatically have the compiled framework being pushed, too
have my be able client to use my Project and work on the Project but only has access to the compiled library so he can't see what's inside it

How to add github project into xcode swift project

I've got an existing Swift project in Xcode and I want to use the functionality of this github project (MangoKitten)
They suggest using Swift Package Manager but when I tried setting up that my Xcode went haywire and would crash every time I tried launching it.
So I've finally managed to undo the damage done from SPM and am trying to just go ahead and add MangoKitten into my project manually so that I can use the functionality it provides with a simple import statement in my viewController.swift
I've never used Github before and I'm relatively new to Swift in general so this is all very confusing.
Is there any simple way to import the github project into my Xcode project without downloading it and adding every single .swift file manually into my project?
Thanks guys.

Build static library Target with main Target for proper architecture in XCode?

I am currently developing an iPhone app in XCode that requires a static library that is built from another XCode project I have made. I currently have both targets in the same project, and I need the static library project to build and run for the proper architecture when I build the project that uses it.
As of now I have to open the static library project on its own, build it from there, find where it was built, and then remove the old library and add the new one to my project that uses it.
How do I do this?
The solution lies within the idea of workspaces. This s.o. thread might also be helpful. I think the general layout youll want to create is a new workspace where you will add both projects, the client and the library, that way they are both within reach.
Best of luck!

Internal Linking of Cocoa Frameworks

In my open-source Cocoa project, I have two Xcode projects -- one framework and one application. I want to link the framework in the application, and whenever I build the framework, I want the linked framework in the application to be updated automatically as well.
What is the correct way to set this up, especially so that someone else who clones my project can easily build both the framework and the application?
Drag the Framework project into the App project's source list (on the left). I make a "Projects" folder in the source list for that exact purpose.
Then, you can simply select your App Target, Get Info, and add the Framework as a Direct Dependency.
Now, whenever you build your App, your Framework will be built as well.
It's recommended to use a common Build Folder as well (Xcode->Preferences->Building) to help with linking.

Resources