Skip to content

Instantly share code, notes, and snippets.

View crispinworsham's full-sized avatar

Crispin Worsham crispinworsham

  • Orange County, California
View GitHub Profile
@cdzombak
cdzombak / CDZScalingButton.h
Created January 21, 2017 16:34
A UIButton with a nice scaling effect when the user touches down on it.
//
// CDZScalingButton.h
// ScalingButton
//
// Created by Chris Dzombak on 10/17/15.
// Copyright © 2015 Chris Dzombak. All rights reserved.
//
@import UIKit;
import UIKit
typealias KeyboardHeightDuration = (height: CGFloat, duration: Double)
// New notification type
let RemoveKeyboardNotifications = "RemoveKeyboardNotifications"
protocol KeyboardAvoidable: class {
var layoutConstraintsForKeyboard: [NSLayoutConstraint] { get }
func addKeyboardObservers()
import Foundation
// MARK: - Protocol
public protocol Notifier {
associatedtype Notification: RawRepresentable
}
public extension Notifier where Notification.RawValue == String {
@jasdev
jasdev / AppDefault.swift
Last active July 19, 2024 15:14
Swift nonmutating Example
import Foundation
enum AppDefault {
case APIServer, runMode, homeDirectory, reactHost
var stringValue: String? {
get {
return NSUserDefaults.standardUserDefaults().stringForKey(String(self))
}
public protocol Selfie: CustomStringConvertible {}
extension Selfie {
var description: String {
let mirror = Mirror(reflecting: self)
return "\(mirror.subjectType)( \(mirror.children.map({ "\($0!): \($1) "}).joinWithSeparator(", ")))"
}
}
@roymckenzie
roymckenzie / KeyboardAvoidable.swift
Last active September 6, 2022 19:42
Easy way to get your view controllers to respect appearance of the keyboard.
// KeyboardAvoidable
// Roy McKenzie
protocol KeyboardAvoidable: class {
func addKeyboardObservers(customBlock: ((CGFloat) -> Void)?)
func removeKeyboardObservers()
var layoutConstraintsToAdjust: [NSLayoutConstraint] { get }
}
var KeyboardShowObserverObjectKey: UInt8 = 1
@JoshuaSullivan
JoshuaSullivan / EnumExample.swift
Last active April 8, 2020 18:03
Don't use Swift enums to box magic strings! Read the blog post: http://www.chibicode.org/?p=16
enum NotificationNames: String {
case UserDataChanged: "UserDataChangedNotificationName"
case ReceivedAlert: "ReceivedAlertNotificationName"
case PeanutButterJellyTime: "ItsPeanutButterJellyTimeNotificationName"
}
@JoshuaSullivan
JoshuaSullivan / Appearance Proxy iOS 9.1.md
Last active August 13, 2016 17:26
Properties and methods of UIKit classes which expose customization via UIAppearance.

UIActivityIndicatorView

@property (nullable, readwrite, nonatomic, strong) UIColor *color NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;

UIBarButtonItem

- (void)setBackgroundImage:(nullable UIImage *)backgroundImage forState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;

- (nullable UIImage *)backgroundImageForState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
import Cocoa
// for-in
func checkForIn(array: [Int], dict: [Int: String]) {
for num in array where dict[num] != nil {
num
}
}
checkForIn([1,2,3,4], dict: [1:"one", 2:"two"])
@s4y
s4y / AppDefault.swift
Created October 12, 2015 17:10
App defaults with an enum
enum AppDefault {
case APIServer, RunMode, HomeDirectory, ReactHost
var stringValue: String? {
get {
return NSUserDefaults.standardUserDefaults().stringForKey(String(self))
}
nonmutating set {
if let newValue = newValue {