Compile and run Apple’s SwiftNIO

Last month, I wrote a post about How to setup SwiftNIO for iOS and tvOS. Basically, I manually create all the targets in a new project, set up everything from scratch. It seems to work.

But it takes time, I don’t like it at all. I think of it and I think I didn’t understand the way how Apple guys set up the project. I missed something.

swift package manager.png

Swift Package Manager

Just yesterday, I realize that Apple guys, they organize the SwiftNIO project around Swift Package Manager.

The package manager has been introduced a couple years ago, but I didn’t mind at all. Because I reply on XCode all the time.

The package manager can do many things, It helps to create, organize the project. It helps manage the dependencies, targets.

Come back to SwiftNIO for instance. Now I’m doing a quick tutorial to compile SwiftNIO and also make an Xcode project file out of it. And you will be able to see how it makes life easier for developers.

Check out Swift-NIO

In this tutorial, I will check out the Swift-NIO release v1.12.0 (not Master, because Apple guys migrating it to Swift 5 at this time)

swift nio release

After download the zip file, We need to unzip it. Then open the terminal, and use the following command to navigate it to the SwiftNIO source folder.

cd "put your directory to swift-nio-1.12.0 here"

 

 

 

Fetch dependencies and build

Because the Swift Package Manager has been in place, so you don’t have to spend much effort here. Use the following command to fetch all the dependency packages.

swift package resolve

You can also use this command (but it is deprecated)

swift package fetch

Now build the project

swift build

 

 

 

Where is output?

That’s it. Super easy, you can have it done in 5 mins. Now navigate to ./.build/debug to see the outcome. (Keep in mind that the .build folder is hidden)

cd ./.build/debug
ls

swift-nio built

One more thing

The last one, I like to share is the swift package manager can help generate an Xcode project file. This is super cool. Let’s try the following command.

swift package generate-xcodeproj

 

 

 

 

That’s it, you can do the same thing on Linux OS like Ubuntu, whatever. Swift Package Manager is awesome, it will be adopted widely, so stay tuned. 🙂

One thought on “Compile and run Apple’s SwiftNIO

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s