Skip to content

Instantly share code, notes, and snippets.

View maximkrouk's full-sized avatar
🇺🇦

Maxim Krouk maximkrouk

🇺🇦
View GitHub Profile
@maximkrouk
maximkrouk / SwiftUI.Font+.swift
Created December 13, 2022 20:42
Conversions between UIKit and SwiftUI fonts
import UIKit
import SwiftUI
extension Font {
public init(uiFont: UIFont) {
self.init(uiFont as CTFont)
}
public func toUIFont() -> UIFont? {
var font: UIFont?
@maximkrouk
maximkrouk / Keyboard.swift
Created January 13, 2022 13:18 — forked from figgleforth/Keyboard.swift
Keyboard input for use with SpriteKit or SceneKit
//
// Keyboard.swift
//
// Created by Bojan Percevic on 5/21/15.
// Copyright (c) 2015 Bojan Percevic. All rights reserved.
//
import AppKit
enum Key: CUnsignedShort {
@maximkrouk
maximkrouk / AsssociatingObject.swift
Created December 28, 2021 09:12
StaticString based object association
import Foundation
public protocol AssociatingObject: AnyObject {
@inlinable
@discardableResult
func setAssociatedObject<Object>(
_ object: Object,
forKey key: StaticString,
policy: objc_AssociationPolicy
) -> Bool
@maximkrouk
maximkrouk / MLWAsyncAVPlayer.h
Created April 21, 2021 07:27 — forked from k06a/MLWAsyncAVPlayer.h
Awesome optimized AVPlayer for smooth scrolling AVPlayerLayer inside UICollectionView/UITableView (tested on iOS10+)
#import <AVFoundation/AVFoundation.h>
@interface MLWAsyncAVPlayer : AVPlayer
@end
@maximkrouk
maximkrouk / !Button.swift
Last active October 16, 2024 14:45
Easily customisable declarative UIKit button
// - Depends on https://github.com/swift-declarative-configuration
// - Depends on https://github.com/swift-foundation-extensions
// - Depends on https://gist.github.com/maximkrouk/942125396a857e49203ddb933d557c31
import UIKit
import FoundationExtensions
import DeclarativeConfiguration
fileprivate extension UIView {
func pinToSuperview() {
// Modification of source: https://github.com/pointfreeco/swift-case-paths/blob/master/Sources/CasePaths/CasePath.swift
/// A path that supports embedding a value in a root and attempting to extract a root's embedded
/// value.
///
/// This type defines key path-like semantics for enum cases.
public struct FunctionalKeyPath<Root, Value> {
private let _embed: (Value, Root) -> Root
private let _extract: (Root) -> Value
@dynamicMemberLookup
@propertyWrapper
public <#class or struct#> <#Prefix#>Box<Content> {
public var content: Content
@inlinable
public var wrappedValue: Content {
get { content }
set { content = newValue }
}
extension <#Box#>: ExpressibleByNilLiteral where Content: ExpressibleByNilLiteral {
@inlinable
public convenience init(nilLiteral: Void) { self.init(nilLiteral: nilLiteral) }
}
extension <#Box#>: ExpressibleByFloatLiteral where Content: ExpressibleByFloatLiteral {
@inlinable
public convenience init(floatLiteral value: Content.FloatLiteralType) {
self.init(.init(floatLiteral: value))
}
@maximkrouk
maximkrouk / IdentifiableBox.swift
Last active June 3, 2020 15:24
Identifiable wrapper for hashable values
@dynamicMemberLookup
@propertyWrapper
public struct IdentifiableBox<Content: Hashable>: Identifiable {
public var id: Int { content.hashValue }
public var content: Content
@inlinable
public var wrappedValue: Content {
get { content }
set { content = newValue }
@maximkrouk
maximkrouk / GenericController.swift
Last active September 13, 2020 21:12
Generic CRUD Controller for Vapor
// Depends on `Builder`: https://gist.github.com/maximkrouk/eede7171952e044492c1fa57291bcf94
// Depends on Model.swift
import Vapor
import Fluent
enum GenericController<Model: APIModel>
where Model.IDValue: LosslessStringConvertible {
/// ID parameter key