Skip to content

Instantly share code, notes, and snippets.

View artemnovichkov's full-sized avatar
👨‍💻
Write code. Blow minds.

Artem Novichkov artemnovichkov

👨‍💻
Write code. Blow minds.
View GitHub Profile
@artemnovichkov
artemnovichkov / rings.png
Last active November 11, 2023 16:13
Activity summary
rings.png
@artemnovichkov
artemnovichkov / image.jpg
Last active April 11, 2024 01:01
👨‍💻 Random Xcode shortcut every day
image.jpg
@artemnovichkov
artemnovichkov / JSONDecoder+Result.swift
Created March 12, 2020 12:29
JSONDecoder + Result
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 {
@artemnovichkov
artemnovichkov / UIApplication+UserInterfaceStyle.swift
Last active December 11, 2020 22:49
Updating application with new user interface style
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
@artemnovichkov
artemnovichkov / UITraitEnvironment.swift
Created December 16, 2019 04:14
Updating layer colors with new trait collection
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
traitCollection.hasDifferentColorAppearance(comparedTo: traitCollection) {
layer.backgroundColor = UIColor.layer.cgColor
}
}
@artemnovichkov
artemnovichkov / UserDefaults+InterfaceStyle.swift
Last active December 25, 2022 12:30
Saving UIUserInterfaceStyle to UserDefaults
public extension UserDefaults {
var overridedUserInterfaceStyle: UIUserInterfaceStyle {
get {
UIUserInterfaceStyle(rawValue: integer(forKey: #function)) ?? .unspecified
}
set {
set(newValue.rawValue, forKey: #function)
}
}
@artemnovichkov
artemnovichkov / UIImageAsset+TraitCollection.swift
Last active December 16, 2019 03:08
An UIImageAsset extension with Dark Mode
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()
@artemnovichkov
artemnovichkov / UIColor+DarkMode.swift
Last active July 3, 2023 14:51
UIColor convenience initializer for Dark Mode
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, *) {
@artemnovichkov
artemnovichkov / ViewController.swift
Last active December 16, 2019 03:18
An example of using Xcode Preview for projects without SwiftUI.
final class ViewController: UIViewController {
}
#if canImport(SwiftUI) && DEBUG
import SwiftUI
struct ViewControllerRepresentable: UIViewRepresentable {
func makeUIView(context: Context) -> UIView {
@artemnovichkov
artemnovichkov / Logging.swift
Created November 21, 2019 04:28
Swift Property Wrapper for logging
@propertyWrapper
struct Logging<T> {
var value: T
init(wrappedValue value: T) {
self.value = value
}
var wrappedValue: T {