Blog

Understanding @dynamicMemberLookup and @dynamicCallable in Swift

Published on

If you have written code in a programming language such as Python or PHP, you can find many direct comparisons to Swift. For one, Swift is statically typed, whereas PHP and Python are not - Swift is considered a safe language as it has a bunch of features to protect you against mistakes - static typing, error throwing, optionality for dealing with nulls, to name a few -, whereas PHP and Python do not.


Writing Command Line Tools in Swift Using ArgumentParser, Part 6: Releasing And Installing Our Command Line Tool

Published on

I wasn’t sure if I should include this article as part of this series. But for the sake of completion, I decided to include it. This article is very short, but it tells us how to actually install our own tool in a system so we can start using it without writing its full path.

To recap, and before I end my series in Swift’s ArgumentParser, let’s give a quick overview of everything we have learned so far:


Writing Command Line Tools in Swift Using ArgumentParser, Part 5: Tools with Asynchronous APIs

Published on

In the past four weeks we have explored many of the features available to us via ArgumentParser and how to use them. Here’s a recap of everything we learned so far:

In this article, we will not explore a feature exposed to us via ArgumentParser. Instead, we will learn how to do something very essential: Creating tools that require asynchronous APIs.


Writing Command Line Tools in Swift Using ArgumentParser, Part 4: Customizing Help

Published on

Writing Command Line Tools in Swift Using ArgumentParser, Part 4: Customizing Help

In the past few weeks, we have explored how to use ArgumentParser and many of its features. It’s great that ArgumentParser provides a lot of functionality for free, but it wouldn’t make sense to build great tools that users can’t figure out how to use. This week is all about that.

We saw how ArgumentParser can build a lot of documentation for free, but we can actually do more. This week, we will explore how we can improve the documentation generated for our command line tools.


Writing Command Line Tools in Swift Using ArgumentParser, Part 3: Subcommands

Published on

We have been having a lot of fun with ArgumentParser in the last two weeks, and the fun is not about to end any time soon. We have explored how we can build basic commands with the basic building blocks of the framework, and how we can perform advanced validation and error handling. This week, we will something very useful: Subcommands.

Subcommands

If you have used git directly from the command line before, you have used subcommands before.


Writing Command Line Tools in Swift Using ArgumentParser, Part 2: Validation & Errors

Published on

Last week we explored how we can build a simple command line tool. We learned how to use @Argument, @Option, and @Flag as the building blocks for ArgumentParser command line tools. We we saw last week was enough to build many simple tools, but there’s still a lot to explore, and cool things to learn.

This week we will learn about input validation and errors, so we can build better tools that take more constrained parameters when relevant.


Writing Command Line Tools in Swift Using ArgumentParser, Part 1: Introduction & Basic Usage

Published on

A few weeks ago, the Swift project introduced the ArgumentParser package. This package makes it easy to write command line tools by providing automatic parsing, documentation generation, and more.

In this article, we will explore ArgumentParser, and how we can start building some command line tools with it, using the basic building blocks, which are three Property Wrappers called Argument, Option, and Flag.

Project Configuration

Open Xcode and create a new project of type “Command Line Tool”. You cannot use this project type for iOS/iPadOS, so if you don’t find it, head over to the Mac tab.


Understanding Function Builders in Swift

Published on

WWDC2020 is just around the corner*, and it hasn’t been one year since WWDC2019 took place. There is still a lot of ground to cover regarding the new tools and APIs demonstrated then. and In this article we will focus on a feature new to Swift itself: Function Builders.

*: Maybe. :(

If you have been hacking away at SwiftUI, you have probably been wondering how it makes it possible to build great UIs with very nice syntactic sugar. Other than property wrappers, SwiftUI is also possible thanks to Function Builders. In this article, we will briefly mention how SwiftUI uses Function Builders, and later we will create our own function builders that have nothing not do with SwiftUI. This way, it will become evident why Function Builders are really neat, and why they don’t have to be strictly tied to SwiftUI.


Finding Related Words with NLEmbedding

Published on

There may be cases in which you need to find related words to others. With the NSLEmbedding class, you can find related strings based on the proximity of their vectors.

Using NLEmbedding

Using NLEmbedding is very straight forward. A simple task is to get an array of related words, which come as an array of (String, NLDistance) back.

The distance between words tells you how “related” they are

let embedding = NLEmbedding.wordEmbedding(for: .english)
let foundWords = embedding!.neighbors(for: "family", maximumCount: 3)
print(foundWords)

In this example, it will print:


Analyzing Natural Language Text with NLTagger

Published on

In the past few weeks, we have explored how we can tokenize natural language text and how to recognize the language a natural language text is written in. This week we will continue exploring more natural language APIs provided by the NaturalLanguage framework. We will learn about the NLTagger class, which allows us to to analyze natural language text to find parts of speech, lexical classes, lemma, scripts, and more. This API, introduced in iOS 12, implements machine learning to work, and just like the other NaturalLanguage classes, is very easy to use.