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
let swift = UTType.swiftSource | |
print(swift) // => Swift Source Code | |
print(swift.rawValue) // public.swift-source | |
print(swift.conforms(to: .sourceCode)) // => true | |
print(swift.declaration?[.conformsTo] as Any) // [ "public.source-code" ] | |
print(swift.declaringBundleURL as Any) // => /System/Library/CoreServices/MobileCoreTypes.bundle | |
print(swift.isDeclared) // => true | |
print(swift.isDynamic) // => false | |
print(swift.preferredTag(for: .filenameExtension) as Any) // => "swift" | |
print(UTType(preferredTag: "swift", for: .filenameExtension, conformingTo: nil) == swift) // => "true" |
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
// | |
// CustomFontMetrics.swift | |
// | |
// Created by Zachary Waldowski on 6/6/17. | |
// Licensed under MIT. | |
// | |
import UIKit | |
private extension UITraitCollection { |
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 | |
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) | |
extension Data { | |
init(referencing data: DispatchData) { | |
self = (data as AnyObject) as! Data | |
} |
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
class MyViewController: UIViewController { | |
var d1: String? | |
var d2: String? = "foo" | |
} | |
let vc = MyViewController() | |
Array(Mirror(reflecting: vc).children) /* => [ | |
(label: "d1" as String?, value: Optional.none as Any), |
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
defaults write com.apple.Safari WebKitMediaPlaybackAllowsInline -bool false | |
defaults write com.apple.SafariTechnologyPreview WebKitMediaPlaybackAllowsInline -bool false | |
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2AllowsInlineMediaPlayback -bool false | |
defaults write com.apple.SafariTechnologyPreview com.apple.Safari.ContentPageGroupIdentifier.WebKit2AllowsInlineMediaPlayback -bool false |
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 | |
/// A type representing an concrete part of an application, such that it can be | |
/// identified in logs. | |
/// | |
/// A typical use is as a nested type: | |
/// | |
/// extension MyViewController { | |
/// enum Log: Error { | |
/// case user |
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 UIViewController { | |
func afterCurrentTransition(_ handler: @escaping(Void) -> Void) { | |
guard let coordinator = transitionCoordinator else { | |
return completion() | |
} | |
coordinator.animate(alongsideTransition: nil, completion: { _ in |
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
// This incantation works well for a fullscreen, paging collection view. | |
// Non-fullscreen works too, with a little finesse. | |
extension MyCollectionViewController { | |
private func updateCollectionViewLayout(forBoundingSize size: CGSize) { ... } | |
override func viewWillAppear(_ animated: Bool) { | |
super.viewWillAppear(animated) | |
updateCollectionViewLayout(forBoundingSize: self.view.bounds.size) |
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 extension NSManagedObjectContext { | |
func executeAsync<T: NSFetchRequestResult>(request: NSFetchRequest, resultsOf _: T.Type = T.self) -> Future<[T]> { | |
let d = Deferred<[T]>() | |
let afr = NSAsynchronousFetchRequest(fetchRequest: request) { results in | |
d.fill(results.finalResult.map({ $0 as! [T] }) ?? []) | |
} | |
do { |