Skip to content

Instantly share code, notes, and snippets.

View drewster99's full-sized avatar

Andrew Benson drewster99

View GitHub Profile
import SwiftUI
extension Binding {
/// Binding to an optional value by providing a defatult value.
///
/// example
///
/// struct Sample: View {
/// @Binding var name: String?
///
@drewster99
drewster99 / AutoResizeViewControllerForKeyboard.swift
Last active January 25, 2021 16:44
Move views out of the way when keyboard appears, Swift 4.1, using Auto-Layout / Interface Builder / Storyboard
{
// Move views when keyboard appears/disappears
// Snipped from ViewController.swift
// This constraint should be tied to the top superview or safe area in Storybaord
@IBOutlet weak var closeButtonTopConstraint: NSLayoutConstraint!
private var topConstraintOriginalConstant: CGFloat?
private var topConstraintScrolledConstant: CGFloat = 0