8 New Ways to Refactor Your Code With Swift 4
Swift is one of the fastest-growing languages in history, due to its elegance, simplicity, and “safety by design”. In fact, Swift’s official mantra is “to make programming simple things easy, and difficult things possible”. In this post, you'll learn how to use Swift to its fullest by refactoring your code.
While a lot of the code optimization is implicit and obviously inherent in the language’s design, there are certain refactoring strategies that can make your code more readable, more reliable, and better performing. In this article, you will learn eight ways to refactor your code with Swift 4.
Objectives of This Article
In this article, you will learn some ways to better optimize and refactor your code with Swift 4. We'll cover the following:
- handling duplicate keys in dictionaries elegantly with zip
- setting default values for dictionaries
- merging dictionaries into one
- filtering data dictionary values directly into another dictionary object
- using Codable to save custom objects into JSON
- swapping values in mutable arrays
- handling multi-line literals
- finding random elements in a collection
Read the complete article, exclusively at envatoTuts+