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
// Swift 3 only; `@noescape` only applies to function definitions (not function types) in 2.x. | |
import CoreData | |
extension NSManagedObjectContext { | |
func performAndWaitOrThrow<Return>(_ body: () throws -> Return) rethrows -> Return { | |
func impl(execute work: () throws -> Return, recover: (Error) throws -> Void) rethrows -> Return { | |
var result: Return! | |
var error: Error? |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<!-- iOS 10, macOS Sierra, and friends bring a new logging subsystem that's | |
supposed to scale from the kernel, up to frameworks, and up to apps. It defaults | |
to a more regimented, privacy-focused approach that large apps and complex | |
systems need. | |
It, along with Activity Tracing introduced in iOS 8 and macOS Yosemite and the | |
Console app in macOS Sierra, hope to help you graduate from caveman debugging to |
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 CoreData | |
@objc(_PersistentStoreDescription) private protocol AnyPersistentStoreDescription: NSObjectProtocol, NSCopying { | |
var type: String { get set } | |
var configuration: String? { get set } | |
@objc(URL) var url: URL? { get set } | |
var options: [String : NSObject] { get } | |
func setOption(_ option: NSObject?, forKey key: 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
// | |
// Activity.swift | |
// | |
// Created by Zachary Waldowski on 8/21/16. | |
// Copyright © 2016 Zachary Waldowski. Licensed under MIT. | |
// | |
import os.activity | |
private final class LegacyActivityContext { |
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 Foundation | |
private extension NSPersonNameComponentsFormatter { | |
static let nameDefaultsByLocale: [String: AnyObject] = { | |
let bundle = NSBundle(forClass: NSPersonNameComponentsFormatter.self) | |
guard let url = bundle.URLForResource("NSPersonNameComponentsFormatterDefaults", withExtension: "plist"), | |
let dict = NSDictionary(contentsOfURL: url) as? [String: AnyObject] else { return [:] } | |
return dict["localeInfo"] as! [String: AnyObject] |
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 Darwin | |
extension Process { | |
// See also: https://github.com/apple/swift/blob/9cdbec13eee72feccfc5f8b987882a8c52e8107b/stdlib/private/SwiftPrivate/IO.swift#L84 | |
public struct Stream: OutputStreamType { | |
private let fd: UnsafeMutablePointer<FILE> | |
private init(fd: UnsafeMutablePointer<FILE>) { | |
self.fd = fd | |
} |
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
private func loadCFunction<Function>(named name: String, ofType _: Function.Type = Function.self) -> Function { | |
let sym = dlsym(UnsafeMutablePointer<Void>(bitPattern: -2), name) // RTLD_DEFAULT | |
return unsafeBitCast(sym, Function.self) | |
} | |
private let CC_SHA1_DIGEST_LENGTH = 20 | |
private let CC_SHA1: @convention(c) (UnsafePointer<Void>, Int32, UnsafeMutablePointer<UInt8>) -> UnsafeMutablePointer<UInt8> = loadCFunction(named: "CC_SHA1") | |
extension 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
import QuartzCore | |
private final class PathContext { | |
let body: CGPath.Element -> Void | |
init(_ body: CGPath.Element -> Void) { | |
self.body = body | |
} | |
} |
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 | |
public protocol NibLoadable: class { | |
static var nibName: String { get } | |
static var nib: UINib { get } | |
} | |
extension NibLoadable { |
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 Foundation | |
let formatter = NSNumberFormatter() | |
formatter.currencyCode = "USD" | |
formatter.numberStyle = .CurrencyStyle | |
formatter.roundingMode = .RoundHalfUp | |
formatter.maximumSignificantDigits = 3 | |
formatter.generatesDecimalNumbers = true | |
formatter.lenient = true |