This file contains hidden or 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
// known-good: Xcode 8.1, Swift 3 | |
extension String { | |
func keepingCharacters(inCharacterSet allowedCharacters:CharacterSet) -> String { | |
var filteredString:String = "" | |
var rangeToCheck:Range<String.Index> = self.startIndex..<self.endIndex | |
while true { | |
if let allowedCharRange = self.rangeOfCharacter(from: allowedCharacters, | |
options: [], |
This file contains hidden or 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
// known-good: Xcode 8, Swift 3 | |
import Foundation | |
var standardError = FileHandle.standardError | |
extension FileHandle : TextOutputStream { | |
public func write(_ string: String) { | |
guard let data = string.data(using: .utf8) else { return } |
This file contains hidden or 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
// kg: Xcode 8, Swift 3 | |
extension FileHandle : TextOutputStream { | |
public func write(_ string: String) { | |
guard let data = string.data(using: .utf8) else { return } | |
self.write(data) | |
} | |
} | |
// now something like: |
This file contains hidden or 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
// known-good. Xcode 8, Swift 3 | |
import XCPlayground | |
/// writes string s to a file in the playground shared directory and returns its URL | |
func write(string s:String, toPlaygroundSharedDataDirectoryFileWithName name:String) -> URL? | |
{ | |
let dirURL:URL = XCPlaygroundSharedDataDirectoryURL as URL | |
let fileURL:URL = dirURL.appendingPathComponent(name) | |
let path = fileURL.path |
This file contains hidden or 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 | |
import AVFoundation | |
/** Returns a UIImageOrientation that will adjust an image | |
- parameter deviceOrientation: physical orientation of the device when the image was captured. Must not be FaceUp or FaceDown | |
- parameter position: position of the camera used for capture. Must be .Front or .Back | |
- returns an UIImageOrientation, which can be used when initializing a UIImageView. | |
This file contains hidden or 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
// overloading on function return values to | |
// enable destructuring a JSON-like type | |
import Foundation | |
enum JSONType { | |
case JBool(Bool) | |
case JNumber(Int) | |
case JString(String) | |
} |
This file contains hidden or 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
// | |
// SettledownTimer.swift | |
// | |
// | |
// Created by Alexis Gallagher | |
// known-good: Swift 2.2, Xcode 7.3.1 | |
// | |
import Foundation |
This file contains hidden or 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
#!/bin/sh | |
command -v carthage >/dev/null 2>&1 || { echo >&2 "I require carthage but it's not installed. Aborting."; exit 1; } | |
carthage update --no-build | |
# A policy proposal: | |
# | |
# We use the "carthage" tool only to download the source code of | |
# third-party libraries that we depend on. |
This file contains hidden or 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
extension NSURL { | |
/// Appends path components to the receiver, optionally specifying if full path is a directory to avoid filesystem access | |
func URLByAppendingPathComponents(pathComponents:[String],lastIsDirectory:Bool? = nil) -> NSURL { | |
guard pathComponents.isEmpty == false else { return self } | |
var newURL = self | |
for idx in pathComponents.startIndex..<pathComponents.endIndex.predecessor() { | |
newURL = newURL.URLByAppendingPathComponent(pathComponents[idx], isDirectory: true) | |
} | |
if let last = pathComponents.last { | |
if let lastIsDirectory = lastIsDirectory { |
This file contains hidden or 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
// known-good: Xcode 7.3.1, Swift 2.2 | |
/** | |
Filters to only those file URLs whose filenames match the glob pattern. | |
- parameter fileURLs: file URLs to filter | |
- parameter filenameGlobPattern: a glob pattern to match against the filename of the file pointed to by a file URL | |
*/ | |
func URLsWithFilenamesMatchingGlobPattern(fileURLs:[NSURL],filenameGlobPattern:String) -> [NSURL] | |
{ | |
let filenamePredicate = NSPredicate(format: "SELF like %@", argumentArray: [filenameGlobPattern]) |