Skip to content

Instantly share code, notes, and snippets.

@erica
erica / gist:06d7e44f4f834757dc36
Last active April 21, 2023 17:14
Exploring
View gist:06d7e44f4f834757dc36
//
// explore.swift
// CmdLineTest
//
// Created by Erica Sadun on 6/25/14.
// Copyright (c) 2014 Erica Sadun. All rights reserved.
//
import Foundation
View CrossPlatformDefines.swift
/*
Erica Sadun, http://ericasadun.com
Cross Platform Defines
Apple Platforms Only
Will update to #if canImport() when available
*/
@erica
erica / regex.swift
Last active December 18, 2022 05:25
View regex.swift
import Foundation
/// Provides NSRegularExpression pattern matching against strings
/// in `switch` expressions
///
/// Regular expressions are expensive to construct. The built-in
/// class cache stores already-constructed pattern instances using
/// the pattern string (coerced to `NSString`) as its keys. Modify
/// matching options at the `match(_, options:)` call-site if needed.
///
@erica
erica / inset.swift
Last active December 12, 2022 05:05
View inset.swift
import Cocoa
public struct UIEdgeInsets {
public var top: CGFloat // specify amount to inset (positive) for each of the edges. values can be negative to 'outset'
public var left: CGFloat
public var bottom: CGFloat
View optionsetstrings.swift
/// Exponentiation operator
infix operator **
extension IntegerArithmetic {
/// Returns base ^^ exp
/// - parameter base: the base value
/// - parameter exp: the exponentiation value
static func **(base: Self, exp: Int) -> Self {
return repeatElement(base, count: exp).reduce(1 as! Self, *)
}
View CGRect+Geometry.swift
/*
erica sadun, ericasadun.com
Core Geometry
*/
import Foundation
import QuartzCore
View Swift Cascading.md

Adding Method Cascades

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

Introduction

Method cascades offer a method-based counterpart to functional chaining. In functional chaining, partial results pass from one step to the next. In cascades, object scope is maintained through a series of sequential calls. Both approaches support fluent interfaces, providing readable streamlined code.

View unwrap.md

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
View throwing.md

Introducing an error-throwing nil-coalescing operator

Introduction

View IDE.txt
/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