Skip to content

Instantly share code, notes, and snippets.

View rnapier's full-sized avatar

Rob Napier rnapier

View GitHub Profile
@jessesquires
jessesquires / generics_playground.swift
Last active June 27, 2018 02:19
Swift optional generic parameters?
protocol FactoryAType {
typealias Product
}
protocol FactoryBType {
typealias Product
}
@rnapier
rnapier / json.swift
Last active January 31, 2024 12:49
Generic JSON Decodable
import Foundation
@dynamicMemberLookup
enum JSON: Codable, CustomStringConvertible {
var description: String {
switch self {
case .string(let string): return "\"\(string)\""
case .number(let double):
if let int = Int(exactly: double) {
return "\(int)"
@lattner
lattner / TaskConcurrencyManifesto.md
Last active May 1, 2024 15:48
Swift Concurrency Manifesto
@rlxone
rlxone / CoreAudio.swift
Last active October 9, 2023 19:46
CoreAudio output device useful methods in Swift 4
/*
static func getOutputDevices() -> [AudioDeviceID: String]?
static func isOutputDevice(deviceID: AudioDeviceID) -> Bool
static func getAggregateDeviceSubDeviceList(deviceID: AudioDeviceID) -> [AudioDeviceID]
static func isAggregateDevice(deviceID: AudioDeviceID) -> Bool
static func setDeviceVolume(deviceID: AudioDeviceID, leftChannelLevel: Float, rightChannelLevel: Float)
static func setOutputDevice(newDeviceID: AudioDeviceID)
static func getDeviceVolume(deviceID: AudioDeviceID) -> [Float]
static func getDefaultOutputDevice() -> AudioDeviceID
*/
import Foundation
public class Disposable {
private var isDisposed = false
private let _dispose: () -> Void
public func dispose() {
if !isDisposed {
_dispose()
isDisposed = true
}