Page 4 of 5

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 Drag and Drop on UITableView for reorder Jul 26 2019

If we use custom cells for a UITableView, and we want to re-order using drag and drop, we need to make our cell model conform to NSItemProviderWriting, NSItemProviderReading and NSObject. To move an object using drag and drop, we need to to be able to serialize and deserialize it. Also, we need to have a drag/drop delegate. Usually, this could be our ViewController.

First, let’s set up our delegate.

UITableViewDragDelegate and UITalbeViewDropDelegate

If we are using our ViewController as the delegate for the drag and drop we need to conform to the protocols UITableViewDragDelegate and UITableViewDropDelegate. To comply with the protocols, we need the following methods:

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...

Creating App Custom URL Scheme Jul 17 2019

We can do this by adding the following fields to the info plist:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
	<key>CFBundleURLTypes</key>
	<array>
		<dict>
			<key>CFBundleTypeRole</key>
			<string>Viewer</string>
			<key>CFBundleURLName</key>
			<string>com.rderik.intoaccountapp</string>
			<key>CFBundleURLSchemes</key>
			<array>
				<string>intoaccountapp</string>
			</array>
		</dict>
	</array>

Or by going to the project info and adding a new URL Type. Create new Custom URL Scheme

The scheme is the one you’ll use to reference the app. For example, when you want to open your app form a today extension, you will use a code similar to the following:

Read More...

Sharing information between iOS app and an extension Jul 16 2019

If you decided to create an Extension for your app (maybe a Today Extension), you will quickly find out that you need to access data from your main app. And soon after, you will find out that you can’t access files in your main app directly from the extension. The process is not as easy as you thought when you started. The good news is that there are a few solutions, and they are not that complicated. In this post, I’ll show you how to use App Groups and embedded frameworks to create the bridge between your app and the extension.

Read More...

UITableView notes Jul 14 2019

There are small details of UITableView that are simple but makes the table view look good. One of those is hiding the separator for empty cells.

A table view has a header, body and footer. Most of the time, when we start a project, we drag a table view but never define the header and footer of the table view, we only use the body. The problem with not having a footer is that the body of the table fills the container, so empty cell separator shows. If we add a footer, even if it is an empty view, this does not occur any more. Let’s first see how to do it via code.

Read More...

Coordinator iOS Jul 12 2019

I am using the coordinator pattern on my Counter App. These are the steps to implement the coordinator pattern.

1. Create a Coordinator protocol.

1
2
3
4
5
6
7
import UIKit

protocol Coordinator {
    var navigationController: UINavigationController { get set }
    
    func start()
}

2. Create a class that implements the Protocol

I normally use AppCoordinator.swift:

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...

Tracking where settings are stored on macOS Jun 28 2019

In this post, I’ll explain how to figure out where macOS stores specific preferences and how to modify them using the command line tool defaults. Knowing where the preferences are stored and how to manage them programmatically allows us to create scripts that will help us automate the setup of one or many computers. I think you’ll find it useful.

I was sharing some code through Slack when I noticed that all my straight quotes (') were replaced by smart quotes (’). I felt cheated, I remember this happening in other apps before, but I’ve stopped myself in the past from fixing it because I don’t want to run after any premature-optimization or automation. The simple solution is to go to Settings > Keyboard > Text and deselect the “Use smart quotes and dashes” checkbox. But how and where do macOS stores user’s preferences?

Read More...

$