Skip to content

Instantly share code, notes, and snippets.

@acchou
acchou / gist:08b2c65d8574f57a055ae262bd2d93b9
Last active February 27, 2018 17:53
Array destructure example
let a = [1, 2, 3];
let [x, y, z] = a; // x = 1; y = 2; z = 3;
//: Playground - noun: a place where people can play
import UIKit
import RxSwift
import RxCocoa
let ps = PublishSubject<Int>()
func pt() -> String {
let thread = NSThread.currentThread()
@acchou
acchou / SupportCode.swift
Last active March 9, 2020 09:04
Playground support code for using RxSwift or any other framework that sends async events.
import Foundation
public func delay(_ delay: TimeInterval, closure: @escaping ()->()) {
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
closure()
}
}
#if NOT_IN_PLAYGROUND
import Foundation
extension String {
// Return a String prefix with UTF8 representation limited to at most maxBytes. If maxBytes is negative, return the original string.
public func prefixUTF8(maxBytes: Int) -> String {
if maxBytes < 0 {
return self
}
// Select the prefix of the string, leaving behind the remaining bytes.
var prefix = self.utf8.prefix(maxBytes)