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 | |
public extension JSONDecoder { | |
func decode<T>(_ type: T.Type, from data: Data) -> Result<T, Error> where T: Decodable { | |
do { | |
let decodedData: T = try decode(T.self, from: data) | |
return .success(decodedData) | |
} | |
catch { |
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 | |
public extension UIApplication { | |
func override(_ userInterfaceStyle: UIUserInterfaceStyle) { | |
if supportsMultipleScenes { | |
for connectedScene in connectedScenes { | |
if let scene = connectedScene as? UIWindowScene { | |
for window in scene.windows { | |
window.overrideUserInterfaceStyle = userInterfaceStyle |
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
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { | |
super.traitCollectionDidChange(previousTraitCollection) | |
traitCollection.hasDifferentColorAppearance(comparedTo: traitCollection) { | |
layer.backgroundColor = UIColor.layer.cgColor | |
} | |
} |
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
public extension UserDefaults { | |
var overridedUserInterfaceStyle: UIUserInterfaceStyle { | |
get { | |
UIUserInterfaceStyle(rawValue: integer(forKey: #function)) ?? .unspecified | |
} | |
set { | |
set(newValue.rawValue, forKey: #function) | |
} | |
} |
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 | |
public extension UIImageAsset { | |
/// Creates an image asset with registration of tht eimages with the light and dark trait collections. | |
/// - Parameters: | |
/// - lightModeImage: The image you want to register with the image asset with light user interface style. | |
/// - darkModeImage: The image you want to register with the image asset with dark user interface style. | |
convenience init(lightModeImage: UIImage?, darkModeImage: UIImage?) { | |
self.init() |
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 | |
public extension UIColor { | |
/// Creates a color object that generates its color data dynamically using the specified colors. For early SDKs creates light color. | |
/// - Parameters: | |
/// - light: The color for light mode. | |
/// - dark: The color for dark mode. | |
convenience init(light: UIColor, dark: UIColor) { | |
if #available(iOS 13.0, tvOS 13.0, *) { |
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
final class ViewController: UIViewController { | |
} | |
#if canImport(SwiftUI) && DEBUG | |
import SwiftUI | |
struct ViewControllerRepresentable: UIViewRepresentable { | |
func makeUIView(context: Context) -> UIView { |
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
@propertyWrapper | |
struct Logging<T> { | |
var value: T | |
init(wrappedValue value: T) { | |
self.value = value | |
} | |
var wrappedValue: T { |
NewerOlder