Page 2 of 3

Understanding the RunLoop model by creating a basic shell Oct 1 2019

When we find ourselves listening for events, reacting to those events, and then going back to listening for more events, we have ourselves an Event-Loop. Having an event-loop is a common scenario. So common that Apple decided to provide us with a model to handle event-loops consistently. In this post, we are going to explore how RunLoops work and use them to build basic shell.

Let’s get started by creating a program that makes use of an event-loop.

Read More...

Using BSD Sockets in Swift Sep 24 2019

Apple provides many useful network frameworks. Network.framework (you can check my previous article on Network.framework if you want to see an example) is the latest. But sometimes we need to go deeper, and the abstractions might get in the way. In this post, we are going to see how to use BSD sockets directly in Swift.

Using BSD sockets means interfacing with C from Swift. Let’s first have a look at some concepts and tips that will help us with using sockets.

Read More...

Understanding Objective-C and Swift interoperability Sep 16 2019

There are many reasons to use more than one programming language in a project. In some cases, a lot of work has gone into building a framework (years maybe). Rewriting the whole framework to have the codebase in the same programming language, might not be the best use of resources. You can see this in macOS between the two main programming languages, Swift and Objective-C (three counting C). In this post, I’ll show how to use Swift code in Objective-C, and how to use Objective-C code in Swift. We are going to explore how the interoperability occurs by building the code manually to get a better understanding.

Read More...

Building a server-client application using Apple's Network Framework Sep 10 2019

Apple’s network APIs are many, the older APIs are well documented, and you’ll find lots of examples. Not so much about the new Network framework. One factor might be that the name is not that search-friendly. In this post, I’ll explain how to use the NWFramework by creating a basic TCP server-client application.

The server will work as an echo, any message received will be sent back to the client. The client will allow us to send messages to the server and display the server response.

Read More...

Building a CLI tool using Swift and Vapor's Console module Jul 30 2019

Building a command-line interface (CLI) tools is a complicated task. We work on the logic of our application and also have to deal with other details like parsing parameters, handling the correct display directives depending on the TTY, etcetera. Vapor, the web framework, uses a module called Console (called ConsoleKit on V4) to build their CLI.

Vapor’s command-line tool provides a lot of functionality, and at the same time, it looks quite smooth. I would like my CLI tools to look more like their command-line tool.

Read More...

Using Swift for scripting Jul 23 2019

Swift is a powerful language. It can be used to create command-line tools, iOS apps, watch OS apps, macOS apps and server-side applications. However, sometimes, we only need to complete a small task, maybe do some automation on our local setup or build a simple script to process data and then send it to another tool. Using Swift for small tasks is what I want to share in this post, not how to build command-line interfaces (CLIs) but how to use the language you already know, Swift, and use it for scripting.

Read More...

Text extraction tools for macOS and iOS app localization Jul 10 2019

Localization is not only translating content but adapting the content to culture, language and customs. This makes our apps more intuitive and engaging for our users. We can localize not only text, but we can also localize images, sounds, shortcuts, etcetera. A crucial part of localization is obtaining the text to be localized. In this post, I’ll focus on text extraction for localization. This post is not a general introduction to localization of apps, but when you finish reading the post, you’ll have a better understanding of crucial aspects of localization and can research other specific topics that you are interested in. As always, check my notes at the end of the posts where I add links and notes to explore related topics, let’s begin.

Read More...

Understanding SSH Keys and using Keychain to manage passphrase on macOS Jul 3 2019

Accessing remote servers using passwords has been discouraged for a long time, and it is suggested to use SSH public keys as the authentication method. I’ve noticed that for some users, the setup and maintenance of their keys becomes a problem, so they go back to using passwords. In this post, I’ll explain how to use SSH keys to login to remote servers and how to set up your SSH configuration to keep track of your keys using the macOS keychain.

Read More...

Setup Swift LSP and Vim Jan 22 2019

With the release of SourceKit-LSP we can run an LSP server for the Swift programming language. That means that we can take advantage of autocompletion and jump to the definition in our text editors that support connection to an LSP server. I’ll show how to set this up using Vim 8.

LAST UPDATED: September/25/2019

First install SourceKit-LSP

Clone the source from the SourceKit-LSP repository

Read More...

Basics of stderr and stdout on Ruby scripts Oct 23 2018

In our scripts, we present information to our users via the two standard output streams: standard output and standard error. In this post, I’ll explain why it is useful to distinguish between standard output and standard error, and share tips on how to interact with the streams when our script’s output is being redirected or used on a non-interactive shell.

The first part is the basics if you already know the basics you can skip to the last section to see an interesting example on how to take advantage of the streams.

Read More...

$