Skip to content

Instantly share code, notes, and snippets.

/*
erica sadun ericasadun.com
Math Types
Swift2
*/
import Foundation
import QuartzCore
public protocol FloatConvertible {
var doubleValue: Double { get }
var floatValue: Float { get }
var intValue: Int { get }
var CGFloatValue: CGFloat { get }
}
public extension FloatConvertible {
public var floatValue: Float {get {return Float(doubleValue)}}
public var intValue: Int {get {return lrint(doubleValue - 0.5)}}

Simplifying guard case/if case syntax

  • Proposal: TBD
  • Author: Erica Sadun
  • Status: TBD
  • Review manager: TBD

Introduction

This proposal simplifies guard case and if case grammar. It drops the case keyword and replaces the assignment sign with the pattern matching (~=) operator. The results are simpler, they reads better, and it transfers the responsibility of saying "this is pattern matching" from case to ~=.

Enhancing closure argument flexibility

Introduction

This proposal loosens closure requirements to support developer flexibility. It removes the _ in requirement that bypasses explicit argument use and allow closures to use any, all, or none of the implicit $n variables as needed or desired.

/*
Erica Sadun, http://ericasadun.com
Cross Platform Defines
Apple Platforms Only
Will update to #if canImport() when available
*/
REMOTE REQUESTS:
com.sadun.airflick
RequestType := show-photo | play-media | screenshot
MediaLocation :=
<url string> | <local file path string> | <array of local file path strings for slideshow>
Rotation := 0 | 1 | 2 | 3 (0 ^, 1 <, 2 v, 3 >)
Transition := SlideRight | Dissolve
SlideDuration := 2 | 3 | 5 | 8 | 10 (Use strings. Incorrect durations default to 5)
// Single Slide
//
// BTHelper.swift
// Buzz
//
// Created by Erica Sadun on 4/17/18.
// Copyright © 2018 Erica Sadun. All rights reserved.
//
import Foundation
import CoreBluetooth
@erica
erica / gist:06d7e44f4f834757dc36
Last active April 21, 2023 17:14
Exploring
//
// explore.swift
// CmdLineTest
//
// Created by Erica Sadun on 6/25/14.
// Copyright (c) 2014 Erica Sadun. All rights reserved.
//
import Foundation
@erica
erica / regex.swift
Last active December 18, 2022 05:25
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
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