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 Combine | |
extension URLSession { | |
/// Returns a publisher that wraps a URL session download task for a given | |
/// URL. | |
/// | |
/// - Parameter url: The URL for which to create a download task. | |
/// - Returns: A publisher that wraps a download task for the URL. |
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
/// A sequence that presents the elements of the base sequence with the | |
/// separator inserted between each element. | |
public struct InterspersedSequence<Base: Sequence> { | |
let base: Base | |
let separator: Base.Element | |
/// Creates a sequence that presents the elements of `base` sequence with the | |
/// `separator` inserted between each element. |
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
extension String.Encoding { | |
init?(charset: String) { | |
let cfencoding = CFStringConvertIANACharSetNameToEncoding(charset as CFString) | |
guard cfencoding != kCFStringEncodingInvalidId else { | |
return nil | |
} |
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 Cocoa | |
extension NSImage.Name { | |
static var amazing: NSImage.Name { | |
return NSImage.Name("AmazingImage!") | |
} | |
} | |
let imageName = String.amazing |
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
extension Int { | |
func isDivisible(by value: Int) -> Bool { | |
return self % value == 0 | |
} | |
} | |
extension Array where Element == Int { |
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 | |
import Accelerate | |
struct Float16 { | |
fileprivate var value: UInt16 | |
init(_ float: Float) { |
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
extension UICollectionViewFlowLayout { | |
typealias DelegateMethod<Key, Value> = ((UICollectionView, UICollectionViewLayout, Key) -> Value) | |
private var delegate: UICollectionViewDelegateFlowLayout? { | |
return collectionView?.delegate as? UICollectionViewDelegateFlowLayout | |
} | |
func retrieve<Key, 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 Foundation | |
extension NSCopying { | |
func copy() -> Self { | |
// Use copy(with zone:) here to disambiguate between this | |
// overload and the one we actually want to call. | |
let c = copy(with: nil) |
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
extension Array { | |
/// Wrapping types for the map function. | |
enum Wrapping { | |
/// Doesn't wrap at all. | |
/// | |
/// When used the resulting array will be one | |
/// element shorter than the input array. | |
case none |
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 | |
/// This manages coalescing multiple calls per frame into a | |
/// single execution of the given block. | |
final class Coalescer { | |
private let notificationCenter: NotificationCenter | |
private let notificationQueue: NotificationQueue | |
private let notificationName = Notification.Name(rawValue: "CoalescingNotification") |