Skip to content

Instantly share code, notes, and snippets.

View andreyoshev's full-sized avatar
🍉
push

Andrey Oshev andreyoshev

🍉
push
View GitHub Profile
@juliensagot
juliensagot / HostingView.swift
Created June 21, 2024 14:22
The missing UIHostingView
import SwiftUI
import UIKit
public final class HostingView: UIView {
public init(@ViewBuilder content: () -> some View) {
super.init(frame: .zero)
let contentView = UIHostingConfiguration(content: content)
.margins(.all, 0)
.makeContentView()
@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
import lldb
def __lldb_init_module(debugger, internal_dict):
debugger.HandleCommand('command script add -f SwiftPrinter.printer pjson')
def printer(debugger, command, result, internal_dict):
debugger.HandleCommand('p print(String(data: try! JSONSerialization.data(withJSONObject:' + command + ', options: .prettyPrinted), encoding: .utf8 )!)')
@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() {
@douglashill
douglashill / updateSafeAreaForKeyboardFromNotification.swift
Last active June 25, 2023 16:11
Avoid the keyboard by leveraging additionalSafeAreaInsets.
// Avoids the keyboard in a UIKit app by leveraging additionalSafeAreaInsets.
// You can put this in the root view controller so the whole app will avoid the keyboard.
// Only tested on iOS 13.3.
// Made for https://douglashill.co/reading-app/
@objc func updateSafeAreaForKeyboardFromNotification(_ notification: Notification) {
guard let endFrameInScreenCoords = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else {
return
}
// Please consider whether the force unwrap here is safe for your own use case.
@arturdev
arturdev / URLRequest+Multipart.swift
Last active February 21, 2023 18:59
URLRequest with multipart support
//
// URLRequest+Multipart.swift
//
// Created by Artur Mkrtchyan on 1/16/19.
// Copyright © 2019 arturdev. All rights reserved.
//
import Foundation
import MobileCoreServices
@sharplet
sharplet / Example.swift
Created November 3, 2017 17:46
An improved wrapper for UIImagePickerController
// Here is a usage example. Refer to ImagePicker.swift below for the implementation!
// 1. Easily configure the picker
let cameraPicker = ImagePicker(sourceType: .camera)
let cropPicker = ImagePicker(sourceType: .photoLibrary, allowsEditing: true)
// Automatically includes both kUTTypeImage and kUTTypeLivePhoto
let livePhotoPicker = ImagePicker(sourceType: .photoLibrary, mediaTypes: [.livePhotos])
// 2. Use the picker