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; | |
NS_ASSUME_NONNULL_BEGIN | |
extern NSString *const GCBConvertedObjCExceptionErrorDomain; | |
extern NSString *const GCBConvertedObjCExceptionUserInfoExceptionKey; | |
typedef NS_CLOSED_ENUM(NSInteger, GCBConvertedObjCExceptionErrorCode) | |
{ | |
GCBConvertedObjCExceptionErrorCodeCaughtException = 1 |
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
/// Creates a pair of sequences built out of an underlying sequence of pairs, i.e. the inverse of `zip(_:_:)`. | |
/// | |
/// let wordsAndNumbers = [ | |
/// ("one", 1), | |
/// ("two", 2), | |
/// ("three", 3), | |
/// ("four", 4) | |
/// ] | |
/// | |
/// let unzipped = unzip(wordsAndNumbers) |
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
{ | |
"fruits" : [ | |
{ | |
"name" : "Apple", | |
"image" : "https://upload.wikimedia.org/wikipedia/commons/thumb/1/15/Red_Apple.jpg/265px-Red_Apple.jpg", | |
"price" : 35 | |
}, | |
{ | |
"name" : "Banana", | |
"image" : "https://upload.wikimedia.org/wikipedia/commons/thumb/4/44/Bananas_white_background_DS.jpg/320px-Bananas_white_background_DS.jpg", |
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 | |
extension UITableView { | |
// Ensures that a dequeued cell is of the expected type and fails with a meaningful message, if it is not. | |
func dequeueReusableCell<Cell>(ofType type: Cell.Type, withIdentifier identifier: String, for indexPath: IndexPath) -> Cell { | |
let cell = dequeueReusableCell(withIdentifier: identifier, for: indexPath) | |
guard let cellOfCorrectType = cell as? Cell else { | |
preconditionFailure("Dequeued cell (\(cell)) was not of expected type (\(type))") |
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 | |
/// Wrapper allowing decoding of arbitrary JSON values, | |
/// i. e. values whose specific type is not known at compile time. | |
/// | |
/// This is a workaround for Swift 4’s decoding system not allowing | |
/// something like `JSONDecoder().decode([String: Any], forKey: .foo)`, | |
/// because `Any` does not (and cannot) conform to `Decodable`. | |
/// | |
/// Access the underlying value using the `anyValue` property. |
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
/// Coordinates access to a critical resources, allowing an arbitrary number of concurrent read operations that are mutually exclusive with single concurrent write operations. | |
/// | |
/// This approach is similar to `dispatch_async()` and `dispatch_barrier_async()`, except access blocks are asynchronous, i.e. the barrier is only released once the access block calls its completion handler. | |
final class AccessCoordinator { | |
private let queue = DispatchQueue(label: "AccessCoordinator") | |
private let lock = NSRecursiveLock() | |
enum AccessType { |
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 { | |
/// A URL identifying the user's home directory, typically in `/Users`. | |
/// | |
/// Calling `NSHomeDirectory()` from a sandboxed app will return an descendant of the app sandbox. | |
/// This property on the other hand will return the actual home directory outside the sandbox. | |
/// Note that access restrictions still apply, e.g. testing access to the returned URL will normally fail. | |
static var actualHomeDirectoryURL: NSURL? { | |
let pw = getpwuid(getuid()) | |
return NSURL(fileURLWithFileSystemRepresentation: pw.memory.pw_dir, isDirectory: true, relativeToURL: nil) |
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
/// A Grand Central Dispatch queue wrapper that manages a serial queue. | |
/// You can dispatch blocks to the receiver asynchronously as well as synchronously | |
/// without running risk of a deadlock. This is in contrast to `dispatch_sync()`. | |
final class SerialQueue { | |
init() { | |
dispatch_queue_set_specific(queue, SerialQueue.queueIdentityKey, queueIdentity, nil) | |
} | |
private let queue = dispatch_queue_create(nil, DISPATCH_QUEUE_SERIAL) |