Swift optional desugaring

Overview

Swift optional desugaring

Setup

Make sure you have installed Swift according to the instructions from you earlier assignment.

Open a terminal / console in this project’s directory, and run the tests:

swift test

You should see 6 tests run, with one failing:

...
<lots of output>
...
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Steps implemented:

✅ Step 0: Original code
❌ Step 1: Remove ?? (nil coalescing)                 (in OptionalDesugaring/DesugaringExercise.swift, line 50)
❌ Step 2: Remove ?. (optional chaining)              (in OptionalDesugaring/DesugaringExercise.swift, line 88)
❌ Step 3: Translate `if let` to `case`               (in OptionalDesugaring/DesugaringExercise.swift, line 118)
❌ Step 4: Translate optional type names to full form (in OptionalDesugaring/DesugaringExercise.swift, line 131)
❌ Step 5: Make implicit optional wrapping explicit   (in OptionalDesugaring/DesugaringExercise.swift, line 160)
❌ Step 6: Verify desugaring using FakeOptional       (in OptionalDesugaring/DesugaringExercise.swift, line 184)

NOTE: The list above only indicates whether a step is implemented,
      not whether it is full desugared or working correctly.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
...
<lots more output>
...
Test Suite 'All tests' failed at 2021-11-24 16:49:29.414.
	 Executed 6 tests, with 1 failure (0 unexpected) in 0.212 (0.214) seconds

The one failure indicates that you have not yet completed all the desugaring tasks.

If you are on a Mac, you can also open the project directory in Xcode and run the tests with cmd-U.

Your task

Briefly study the model in Sources/Model.swift. This example shows an app in which users may have a custom avatars and theme colors for their profile.

Take a look in Sources/OptionalDesugaring/DesugaringExercise.swift. This file starts with a snippet of code that returns the user’s custom background color if present, and the app’s default otherwise. The model is contrived so that several different things here are optional, but the implementation correctly handles all of them using Swift’s syntactic sugar.

Follow the instructions in the file to successively remove Swift’s syntactic sugar for optionals.

When you are done, double check that all the tests passing, then commit and push.

You might also like...
An Xcode playground showcasing the new features in Swift 4.0.
An Xcode playground showcasing the new features in Swift 4.0.

What’s new in Swift 4 An Xcode playground showcasing the new features in Swift 4.0. As seen in the What’s New in Swift session at WWDC 2017. Written b

📖 Design Patterns implemented in Swift 5.0

📖 Design Patterns implemented in Swift 5.0

List of awesome iOS & Swift stuff!!
List of awesome iOS & Swift stuff!!

Awesome iOS Developer Feel free to fork this repository and pull requests!! 🔎 Content Coding Convention Swift Lint Design Pattern Adaptor Delegation

This repo shows how to set up and use GitHub Actions as a CI for Swift Packages
This repo shows how to set up and use GitHub Actions as a CI for Swift Packages

SwiftPackageWithGithubActionsAsCI This repo shows how to set up and use GitHub Actions as a CI for Swift Packages. Available environments on GitHib Li

The first HackingWithSwift project from the 100 Days of Swift series.

StormViwer A gallery to display images included in the app's internal assets folder. This is my first ever swift project and it is a part of the serie

Mini-application iOS native avec Xcode et Swift exploitant l'architecture MVVM et le framework Combine d'Apple pour la mise en place de la programmation réactive fonctionnelle, le tout avec UIKit.
Mini-application iOS native avec Xcode et Swift exploitant l'architecture MVVM et le framework Combine d'Apple pour la mise en place de la programmation réactive fonctionnelle, le tout avec UIKit.

iOS (Swift 5): Test MVVM avec Combine et UIKit L'architecture MVVM et la programmation réactive fonctionnelle sont très utlisées dans le développement

iOS native app demo with Xcode and Swift using MVVM architecture and Apple's Combine framework for functional reactive programming, all with UIKit
iOS native app demo with Xcode and Swift using MVVM architecture and Apple's Combine framework for functional reactive programming, all with UIKit

iOS (Swift 5): MVVM test with Combine and UIKit MVVM and functional reactive programming (FRP) are very used in iOS development inside companies. Here

A treelist ViewController that implemented with Uikit (swift).
A treelist ViewController that implemented with Uikit (swift).

TreeList ViewController A treelist viewcontroller that implemented with Uikit (swift). Features The sections could be expanded and folded by clicking

USC's ITP342 iOS Development Swift Final Project

READMEBlogs USC's ITP342 iOS Development Swift Final Project NOTE: You'll need to attach your own Firebase to the app LINK TO APP ZIP FILE: https://dr

Owner
null
SwiftLint - A tool to enforce Swift style and conventions, loosely based on Swift Style Guide.

SwiftLint - A tool to enforce Swift style and conventions, loosely based on Swift Style Guide.

Realm 16.9k Dec 30, 2022
Sweet-swift - Make Swift Sweet by Gracefully Introducing Syntactic Sugar, Helper Functions and Common Utilities

Sweet Swift Make Swift Sweet by Gracefully Introducing Syntactic Sugar, Helper F

Yanzhan Yang 2 Feb 6, 2022
Airbnb's Swift Style Guide.

Airbnb Swift Style Guide Goals Following this style guide should: Make it easier to read and begin understanding unfamiliar code. Make code easier to

Airbnb 1.8k Jan 3, 2023
LinkedIn's Official Swift Style Guide

Swift Style Guide Make sure to read Apple's API Design Guidelines. Specifics from these guidelines + additional remarks are mentioned below. This guid

LinkedIn 1.4k Jan 5, 2023
The Official raywenderlich.com Swift Style Guide.

The Official raywenderlich.com Swift Style Guide. Updated for Swift 5 This style guide is different from others you may see, because the focus is cent

raywenderlich 12.5k Jan 3, 2023
A self-taught project to learn Swift.

30 Days of Swift Hi Community I am Allen Wang, a product designer and currently learning Swift. This project was totally inspired by Sam Lu's 100 Days

Allen Wang 11.4k Dec 31, 2022
Explanations and samples about the Swift programming language

About Swift Contents Explanations and samples about: Swift Programming Language Swift Standard Library Target audience Developers familiar with object

Nicola Lancellotti - About 74 Dec 29, 2022
A collection useful tips for the Swift language

SwiftTips The following is a collection of tips I find to be useful when working with the Swift language. More content is available on my Twitter acco

Vincent Pradeilles 929 Dec 10, 2022
Swift Featured Projects in brain Mapping

Swift 开源精选   自 2014年 WWDC 发布 Swift 语言以来,本项目 一直致力于将主流 Swift 中文学习、开发资源汇集于此,并且尽力紧密地跟踪、甄选优秀 Swift 开源项目,以方便开发者快速获得并使用。考虑 Swift 已经正式发布超过四年半(更无力管理维护海量的 Swift

iPader 15.8k Jan 9, 2023
A collection of Swift tips & tricks that I've shared on Twitter

⚠️ This list is no longer being updated. For my latest Swift tips, checkout the "Tips" section on Swift by Sundell. Swift tips & tricks ⚡️ One of the

John Sundell 3.9k Dec 30, 2022