Skip to content

Instantly share code, notes, and snippets.

@AfricanSwift
AfricanSwift / Default values for enum associated values.md
Last active October 28, 2019 17:49
Evolution Proposal: Default values for enum associated values

Default values for enum associated values

  • Proposal: SE-XXXX
  • Author: African Swift
  • Status: Draft
  • Review manager:

Introduction

Support default values for enum associated values.

@AfricanSwift
AfricanSwift / mutable_loop_index.swift
Last active January 8, 2016 21:13
c loops with mutable index, advance or rewind index
// The below code segment is an extraction from a compression routine for Ansi (ECMA 48) tags
// For example:
// All Ps functions are compressed through summation of Ps values, for example:
// \u{1b}[1C\u{1b}[3C\u{1b}[1B\u{1b}[1B\u{1b}[1B = \u{1b}[4C\u{1b}[3B
// All CSI Pm functions are compressed with a semicolon delimiting sub Pm values, for example:
// \u{1b}[1m\u{1b}[30m\u{1b}[45m = \u{1b}[1;30;45m
let tagArray = self.toString().characters.split(
isSeparator: { String($0) == Ansi.C0.ESC } ).map { Ansi.C0.ESC + String($0) }
@AfricanSwift
AfricanSwift / Loop_Index_Mutability.swift
Last active December 8, 2015 18:43
Issues with index mutation in a loop
/*
Behaviour below is consistent with inline declaration,
index correctly mutates each interation
*/
for var index = 0; index < 10; index += 1 {
index += 2 //mutable index
print(index, terminator: " ") // output = 2 5 8 11
}
print("")
@AfricanSwift
AfricanSwift / uglyoption.swift
Last active November 26, 2015 20:45
radex ugly option
private func handleNotificationAction(id: String?, userInfo: [NSObject: AnyObject], responseInfo: [NSObject: AnyObject]?, completion: () -> Void) {
// inline our id choices
enum idOptions: String {
case comment, invitation_accept, invitation_decline, star, complete, show, delegate, none
static var project: [idOptions] = [.invitation_accept, .invitation_decline]
static var task: [idOptions] = [.star, .complete]
}
// Unwrap optionals