Skip to content

Instantly share code, notes, and snippets.

View tsraveling's full-sized avatar

Tim Raveling tsraveling

View GitHub Profile
var keyboardHeight : CGFloat = 0
func textFieldDidBeginEditing(_ textField: UITextField) {
let y = textField.frame.origin.y
let h = self.scrollView.frame.size.height
let margin = h - (keyboardHeight + textField.frame.size.height)
self.scrollView.setContentOffset(CGPoint(x: 0, y: y >= margin ? y - margin : 0), animated: true)
}
// Do this next part in the background
DispatchQueue.global(qos: .userInitiated).async {
// Do your time-costly work here
// Return to the main thread to update the UI
DispatchQueue.main.async {
// Perform UI updates here
}
@tsraveling
tsraveling / copy-to-clipboard.swift
Last active April 19, 2017 23:00
Copy to clipboard
let clipboard = UIPasteboard.general
clipboard.string = <#T##string#>
@tsraveling
tsraveling / protocol.md
Created April 20, 2017 22:04
Init PyPEG 2

PyPeg2 Setup

1. Set up virtualenv

Using Terminal:

> cd project_root
virtualenv env
source env/bin/activate
@tsraveling
tsraveling / String+Error.swift
Created April 21, 2017 05:42
Strings as errors
extension String: LocalizedError {
public var errorDescription: String? { return self }
}
@tsraveling
tsraveling / common-formats.swift
Last active September 9, 2017 22:03
Date Formats
let shortest_date = "M.d.yy" // 1.15.17
let short_date = "M.d.yyyy" // 1.15.2017
let full_date = "MMMM d, yyyy" // January 15, 2017
@tsraveling
tsraveling / FacebokHandler.swift
Last active April 25, 2017 18:47
Facebook Integration
import FacebookCore
@tsraveling
tsraveling / protocol.md
Last active April 26, 2017 18:34
Twitter Integration

Twitter sharing

1. Install TwitterKit

Use Fabric. Make sure to reference the right app in info.plist -> Fabric -> Kits.

2. In VC:

Import:

@tsraveling
tsraveling / table-header-text.swift
Created April 25, 2017 17:31
Set UITableView header text color
func tableView(_ tableView: UITableView, willDisplayHeaderView view:UIView, forSection: Int) {
if let headerView = view as? UITableViewHeaderFooterView {
headerView.textLabel?.textColor = .white
}
}
@tsraveling
tsraveling / Array+Params.swift
Created April 25, 2017 23:18
Extend Params Dictionary
extension Dictionary where Key: ExpressibleByStringLiteral, Value:Any {
}