Skip to content

Instantly share code, notes, and snippets.

/// An indexed tuple specifically for use with enumerated results
public typealias Indexed<Index, Value> = (index: Index, value: Value)
public extension Array {
/// Establishes a lazy sequence of enumerated items using index and value labels
public func indexed() -> LazyMapSequence<EnumeratedSequence<[Element]>, Indexed<Index, Element>> {
return enumerated()
.lazy
.map({ return $0 as Indexed<Index, Element> })
@erica
erica / lns.swift
Last active April 26, 2025 13:09
#!/usr/bin/xcrun swift
import Cocoa
let manager = FileManager.default
// NSString workarounds
extension String {
var lastPathComponent: String {
return (self as NSString).lastPathComponent
}
func appendingPathComponent(_ string: String) -> String {
/*
Erica Sadun, http://ericasadun.com
Cross Platform Defines
Apple Platforms Only
Will update to #if canImport() when available
*/
var count = 0
let headranges: [Range<Int>] = [0x00A1...0x00A7, 0x00B0...0x00B1, 0x2016...0x2017, 0x2020...0x2027, 0x2030...0x203E, 0x2041...0x2053, 0x2055...0x205E, 0x2190...0x23FF, 0x2500...0x2775, 0x2794...0x2BFF, 0x2E00...0x2E7F, 0x3001...0x3003, 0x3008...0x3030]
let headchars = [0x00A9, 0x00AB, 0x00AC, 0x00AE, 0x00B6, 0x00BB, 0x00BF, 0x00D7, 0x00F7]
let charranges: [Range<Int>] = [0x0300...0x036F, 0x1DC0...0x1DFF, 0x20D0...0x20FF, 0xFE00...0xFE0F, 0xFE20...0xFE2F, 0xE0100...0xE01EF]
print("Operator Heads")
print("/­ =­ -­ +­ !­ *­ %­ <­ >­ &­ |­ ^­ ~­ ?­")
for value in headchars {
print(String(UnicodeScalar(value)), terminator:" ")
/*
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.

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