$ echo 'public func f() { print("YES") }' > x.swift
$ swiftc -emit-library -emit-module -module-link-name x x.swift
$ swift -L . -I .
Welcome to Apple Swift version 5.4 (swiftlang-1205.0.26.9 clang-1205.0.19.55).
Type :help for assistance.
1> import x
import x
2> f()
f()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NRTRootViewController.m | |
// GradientTableView | |
// | |
// Created by Rick Harrison on 8/15/13. | |
// Copyright (c) 2013 Rick Harrison. All rights reserved. | |
// | |
#import "NRTRootViewController.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// Playground - noun: a place where people can play | |
class Channel<T> { | |
var stream: Array<T> | |
let queue: dispatch_queue_t | |
let semaphore: dispatch_semaphore_t | |
init() { | |
self.stream = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NSManagedObjectContext+DebugSwizzling.h | |
#import <CoreData/CoreData.h> | |
#if DEBUG | |
/** | |
* Toggles debugging of Core Data managed object contexts. | |
* | |
* When enabled, will fire NSLogs in the following cases: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
http://rosettacode.org/wiki/Handle_a_signal | |
Most general purpose operating systems provide interrupt facilities, sometimes called signals. | |
Unhandled signals generally terminate a program in a disorderly manner. Signal handlers are | |
created so that the program behaves in a well-defined manner upon receipt of a signal. | |
For this task you will provide a program that displays a single integer on each line of output at | |
the rate of one integer in each half second. Upon receipt of the SigInt signal (often created by the user typing ctrl-C) | |
the program will cease printing integers to its output, print the number of seconds the program has run, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Examples | |
var set = AnySet() | |
set.insert(3) | |
set.insert("hello") | |
set.insert("hi") | |
set.insert(2.3) | |
set.contains(6) // -> false | |
set.contains(3) // -> true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add subtitle track | |
MP4Box -add minecraft_uncut.srt:lang=eng:layout=0x60x0x-1:group=2:hdlr="sbtl:tx3g" Minecraft2_mobile.mp4 | |
# Add audio track | |
# 1. doesnt work in quicktime/itunes | |
MP4Box -add commentary_audio.aac Minecraft2_mobile.mp4 | |
# 2. supposed to work in quicktime/itunes but doesn't seem to; :name at least is definitely not supported | |
MP4Box -add commentary_audio.aac:disable:group1:lang=en:name="Director's Commentary" Minecraft2_mobile.mp4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Darwin | |
@dynamicMemberLookup | |
struct Environment { | |
subscript(dynamicMember name: String) -> String? { | |
get { | |
guard let value = getenv(name) else { return nil } | |
return String(validatingUTF8: value) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Wait for async operation to return value and call callback with the value | |
/// This class is intended to workaround/simplify async/await + actors isolation | |
/// https://twitter.com/krzyzanowskim/status/1523233140914876416 | |
private class AsyncWaiter<T> { | |
var didReceiveValue: Bool = false | |
let value: (T) -> Void | |
let operation: () async throws -> T | |
init(_ value: @escaping (T) -> Void, operation: @escaping () async throws -> T) { | |
self.value = value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIResponder { | |
private weak static var _currentFirstResponder: UIResponder? = nil | |
public static var current: UIResponder? { | |
UIResponder._currentFirstResponder = nil | |
UIApplication.shared.sendAction(#selector(findFirstResponder(sender:)), to: nil, from: nil, for: nil) | |
return UIResponder._currentFirstResponder | |
} |
OlderNewer