Skip to content

Instantly share code, notes, and snippets.

View xmollv's full-sized avatar

Xavi Moll xmollv

View GitHub Profile
@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.
@parrots
parrots / AsyncOperation.swift
Last active May 17, 2021 10:44
A Swifty version of an AsyncOperation which solves two common problems I ran into. (see comment below for issues addressed)
//
// AsyncOperation.swift
// Slopes
//
import Foundation
class AsyncOperation: Operation {
private let stateLock = NSLock()
private var observers: [NSKeyValueObservation] = [NSKeyValueObservation]()
@calebd
calebd / ActionSheetPresentationController.swift
Created July 18, 2017 02:42
Action Sheet Presentation Controller
// Created by Caleb Davenport on 7/14/17.
import UIKit
final class ActionSheetPresentationController: UIPresentationController {
// MARK: - Properties
private var dimmingView: UIView!