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 Combine | |
protocol HasCancellables: AnyObject { | |
var cancellables: Set<AnyCancellable> { get set } | |
} | |
extension HasCancellables { | |
var cancellables: Set<AnyCancellable> { | |
get { |
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 | |
protocol Reusable { | |
static var reuseIdentifier: String { get } | |
} | |
extension Reusable { | |
static var reuseIdentifier: String { | |
String(describing: self) | |
} |
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 UIKit | |
extension AppDelegate { | |
func changeUserInterfaceStyle() { | |
guard let window = window else { return } | |
if window.overrideUserInterfaceStyle == .unspecified { | |
window.overrideUserInterfaceStyle = UIScreen.main.traitCollection.userInterfaceStyle == .light ? .dark : .light | |
} else { | |
window.overrideUserInterfaceStyle = window.overrideUserInterfaceStyle == .light ? .dark : .light |
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
<?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"> | |
<dict> | |
<key>FILEHEADER</key> | |
<string> | |
// ___FILENAME___ | |
// ___PROJECTNAME___ | |
// | |
// Copyright (c) ___YEAR___ ___ORGANIZATIONNAME___. All rights reserved. |
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 String { | |
subscript(range: String.IndexDistance) -> Character { | |
self[index(at: range)] | |
} | |
subscript(range: NSRange) -> Substring { | |
self[range.lowerBound..<range.upperBound] | |
} |
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 String { | |
subscript(safe range: String.IndexDistance) -> Character? { | |
guard let index = index(at: range) else { return nil } | |
return self[index] | |
} | |
subscript(safe range: NSRange) -> Substring? { |
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 Collection { | |
subscript(safe index: Index) -> Element? { | |
indices.contains(index) ? self[index] : nil | |
} | |
subscript(safe range: Range<Index>) -> SubSequence? { | |
indices.contains(range.lowerBound) && indices.contains(range.upperBound) ? self[range] : 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 UIKit | |
extension UIView { | |
func ancestorView<T: UIView>() -> T? { | |
var view = superview | |
while view != nil && !(view is T) { | |
view = view?.superview | |
} | |
return view as? T |