Skip to content

Instantly share code, notes, and snippets.

Better Unwrapping

Unwrapping values is one of the most common Swift tasks and it is unnecessarily complex.

Consider the following solutions:

  • Introduce an unwrap keyword for Optional values
  • Introduce an Unwrappable protocol for associated-value enumerations.
  • Apply unwrap to non-Optional values.
@erica
erica / throwing.md
Last active February 26, 2022 04:51

Introducing an error-throwing nil-coalescing operator

Introduction

/Applications/Xcode-beta.app/Contents/Frameworks/IDEFoundation.framework/IDEFoundation
IDEManageCertificates
IDEDistributionShouldCleanUpAfterExport
IDEProvisioningErrorDomain
IDEProvisioningError_UserInfoKey_IDEProvisionableName
IDEProvisioningError_UserInfoKey_IDEProvisioningUserAction
IDEProvisioningError_UserInfoKey_IDEProvisioningErrorAction
IDEProvisioningError_UserInfoKey_IDEProvisioningErrorTeam
IDEProvisioningError_UserInfoKey_IDEProvisioningErrorPlatform

Book Ideas

  • Preview Power: AKA free, fun, no fotoshop. If you've taken my webinar on this, you pretty much know what's involved. Lots of stuff with a surprisingly powerful features that not a lot of people know about.
  • ed-ucation: Write a book on using ed because it's the best editor ever and it's more or less guaranteed to be available on every *nix ever. g/re/p for life. Plus nods to sed, vi, etc.
  • hidden macOS gems: uncovering the coolness that's already there on your machine.
  • Swift at the Command Line: from emitting proper exit codes to using the argument parser, input and output streams, etc. More involved than the webinar, and can extend to coloring text at the command line, curses, etc depending on how obscure I get. Or I can pull back and focus just on the argument parser.
  • Xcode Power Up: If you've attended my webinar, you know what this is. Twists and secrets.
  • Zero to SwiftPM: If you've attended my webinar, you know what this is.
  • **N Unix Obscurities (BSD and GN
import Foundation
let string = """
Wordle 204 6/6
⬜⬜⬜⬜🟨
🟨🟨⬜⬜⬜
⬜🟩🟩🟨⬜
⬜🟩🟩⬜🟩
⬜🟩🟩⬜🟩
1d0
< import AppKit
9a9
> import StoreKit
10a11
> import UIKit
25,35c26,28
< @available(OSX 10.15, *)
< @available(iOS, unavailable)
< @available(tvOS, unavailable)
// Returns `URL?`
public enum SocketEndPoint: String {
case eventSocket = "http://nowhere.com/events"
case liveSocket = "http://nowhere.com/live"
public var url: URL? {
return URL(string: self.rawValue)
}
}

Changing the Behavior of StrideThroughGenerator

  • Proposal: TBD
  • Author(s): Erica Sadun
  • Status: TBD
  • Review manager: TBD

Swift offers two stride functions, stride(to:, by:) and stride(through:, by:). I propose to introduce a third style that changes the way the through variation works and address inherent issues with floating point strides.

This proposal was discussed on-list in the "[Discussion] stride behavior and a little bit of a call-back to digital numbers" thread.

import UIKit
/// High precedence
precedencegroup HighPrecedence { higherThan: BitwiseShiftPrecedence }
/// Exponentiation operator
infix operator **: HighPrecedence
extension CGFloat {
/// Returns base ^^ exp
/*
Erica Sadun, http://ericasadun.com
*/
import Foundation
// --------------------------------------------------
// MARK: Foundation Interop