Skip to content

Instantly share code, notes, and snippets.

Erica Sadun erica

Block or report user

Report or block erica

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Approach1.swift
// Returns `URL?`
public enum SocketEndPoint: String {
case eventSocket = ""
case liveSocket = ""
public var url: URL? {
return URL(string: self.rawValue)
View playgroundRender.swift
import PlaygroundSupport
import SwiftUI
extension UIView {
var renderedImage: UIImage {
let image = UIGraphicsImageRenderer(size: self.bounds.size).image { context in
UIColor.lightGray.set(); UIRectFill(bounds)
self.layer.render(in: context.cgContext)
return image
View circleintersection.swift
import UIKit
/// High precedence
precedencegroup HighPrecedence { higherThan: BitwiseShiftPrecedence }
/// Exponentiation operator
infix operator **: HighPrecedence
extension CGFloat {
/// Returns base ^^ exp
View linuxreadwrite.swift
import Glibc
// Swift 3 version here:
Did a bunch of tweaks this morning:
removed == true (sorry Kametrixom!)
cleaned up both stringFromBytes and bytesFromString
changed fperror check to guard
replaced use of 1024 in several places with a single constant
View miband.swift
import Cocoa
import CoreBluetooth
import PlaygroundSupport
public class BTHelper: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate {
// BLE Access
var centralManager: CBCentralManager
override init() {
self.centralManager = CBCentralManager(delegate: nil, queue: nil)
View invariant.swift
extension Never {
/// A developer facing statement explaining how program correctness has failed.
public struct Reason: CustomStringConvertible {
public let description: String
public init(_ rationale: String) {
self.description = rationale
View gist:0c445044e1bf97778263


How To Get Answers

Ask your question and then be patient. Tell us what you want to happen, what is actually happening, and include any error messages you find:

  • Provide a scenario. "I am trying to do X, I do so by calling APIs W and Y, but Z happens instead. I see the following error messages:..."
  • Focus on the goal. Ask about what you're trying to achieve (the big story) rather than the specific technical detail that you believe is holding you back.
  • Don't solicit help. Don't say, "Does anyone here know about (for example) Protocol Extensions". Just ask your question.
  • Do your homework. Search the web before asking in-channel.
  • Be courteous Don't just paste Stack Overflow questions in-channel.
  • Remember the topic Refer questions about third party libraries to their developers.
erica /
Last active Aug 15, 2019
Introducing Role Keywords to Protocol Implementations

Introducing Role Keywords to Protocol Implementations to Reduce Code Errors


This proposal eliminates several categories of user errors. It mitigates subtle, hard-to-find bugs in Swift protocol code that compile without warning. Introducing "role" keywords that document code intent will increase protocol safety and enable the compiler to test for issues by matching desired behaviors against actual code.

View monoid.swift
import Foundation
// 3456789012345678901234567890123456789012345678901234567890123456789012345678
Monoid reduction, for strictly binary operation combination.
Note: The monoid approach does not throw right now.
You can’t perform that action at this time.