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:

  1. handling duplicate keys in dictionaries elegantly with zip
  2. setting default values for dictionaries
  3. merging dictionaries into one
  4. filtering data dictionary values directly into another dictionary object
  5. using Codable to save custom objects into JSON
  6. swapping values in mutable arrays
  7. handling multi-line literals
  8. finding random elements in a collection


Read the complete article, exclusively at envatoTuts+
Doron KatzSwift, iOS12