To describe building and publishing your swift package in this post.
Introduction
Try to make Swift Package
and publish it on GitHub.
My environment is as follows:
|
|
Creat Swift package project
In Xcode 12, User can create a swift package project on the one.
- Click
File > New > Swift Package...
of Xcode's menu. - Enter
Ctrl + Shift + Command + N
But currently requires some command line operations.
Previously, you had to use the following command.
|
|
Package.swift and dependency description
Swift Package require that describe the dependency of another swift package to Package.swift
.
It seems that adding a dependency cannot be done from the Xcode menu, so Package.swift
edit it directly.
The steps are the following two points.
- Describe the URL and version of the package
- Describe the package name in the Target you want to depend on
The source code below describes Package.swift
the URL and version of the dependent package in the initial state of dependencies: []
.
|
|
For example, to add the HTTP library Alamofire to a dependency:
|
|
Package.swift
when you save, Xcode will go to get the package added to the dependency,
and the dependency will be displayed as shown in the red frame in the figure below.
Now, write the package name in Target that you want to depend on next.
So let's check the package name of the added package.
In the case of Alamofire, It's a Swift Package Dependencies > Alamofire > Package.swift
description as shown in the figure below.
Did you find package name?
Then, you could append your Package.swift
.
Updated Package.swift
is here:
|
|
Create an Xcode project on the command line.
|
|
Let's build it.
|
|
If the build is successful, Teams.framework will be generated.
And Deployment Target
what about the settings of this framework?
Let's look that is the red frame in the figure below.
Oh, it's a little old. Since the latest iOS is 14 series, 9 series will support 6 generations. This is too painful. Let's change it.
|
|
Once you've made your changes, recreate your Xcode project on the command line.
|
|
If you check the Deployment Target
, you can see that it has changed.
If you checked the results that added the dependencies, let's push the code to GitHub and actually incorporate it next.
Built into App project
Let's create an app project and incorporate your own Swift Pakcage. It doesn't matter which platform the app project uses, but I'm using tvOS (Apple TV). Also, select Swift UI to use it in the examples below.
Xcode has feature that add Swift Package. But since versioning isn't set in it, specify the branch as shown in the figure below.
When you create a Swift Package in Xcode, to fix a {package name}.swift in Sources/{package name}.
In the example, the package name is Teams
, so it will be as follows.
|
|
If you fixed it then push the code to GitHub.
Click File > Swift Packages > Update to Latest Package Versions
to get the latest code in your app project.
Fix ContentView.swift
in the app project.
|
|
If app displayed 'sample' in, it's successful.
Conclusion
In this post, i introduced the flow that create Swift Package and publish it on GitHub. Next time, I' ll want to post an advanced edition that has relying on the C ++ library.