How to build a Vapor Docker image with an environment variable?

I use Docker images when developing apps with Vapor. It’s a great way to run the code in the final deployment environment right from the start of the project. I use environment variables to direct the code execution and Docker provides a nice way to set them when building an…

Sharing data between an app extension and a containing app in macOS

I was developing a Safari App Extension and needed a way to share data between the containing app and the extension. I needed to pass the user settings, so the extension would behave correctly. The containing app does not have a direct access to the extension’s properties and vice versa….

How to solve Command CodeSign failed with a nonzero exit code error

I was building a macOS app and wanted to rename the XCode project. I carefully changed the project name, folder and filenames and updated the settings. Then I did a clean build and run the app. Everything worked like a charm. However when I tried to run unit tests I…

How to change Windows/DOS line breaks to Unix style with Vi

I had a file that was edited in Windows, so it had CRLF line breaks. It was a script and I had to change the line breaks to LF before I could run the script in bash. I converted the line breaks to Unix style using the vi editor and…

How to verify if server supports TLS 1.2

I was implementing an Apple Pay functionality for a website and one of the requirements was that the server must support the Transport Layer Security (TLS) 1.2 protocol. There was an easy way to check that from MacOS command line. openssl s_client -connect example.com:443 -tls1_2 I got a certificate chain…

How to set a port number for Vapor server on localhost

Vapor defaults to port 8080 on localhost. I couldn’t use the 8080, since that was reserved for another server on my MacBook Pro. Here’s how I set a different port number from the command line. swift run Run –hostname localhost –port 9000 This works with Vapor Framework 3.0.8 and Toolbox…

Using DispatchSemaphore to control asynchronous resources

A counting semaphore is a way of controlling access to a resource from multiple contexts. It can be also a solution for handling asynchronous methods in command line utilities. I was making a command line utility to access REST APIs recently. I needed a way to make sure that the…

How to make a progress bar for WKWebView

Progress bar is a nice way of showing users that our app is downloading content and things are progressing. The progress bar can be placed anywhere on the screen, but it is usually a thin line just under the navigation bar. We can create a progress bar programmatically and set…