Skip to content

Instantly share code, notes, and snippets.

Avatar

A Wild Austin Feight feighter09

View GitHub Profile
@feighter09
feighter09 / ParseColumnAdder
Last active Aug 29, 2015
Add many Parse columns at once
View ParseColumnAdder
// Populate the array with subarrays of [ColumnName, ColumnType]
// where columnType is one of: ["String", "Number", "Boolean", "Date", "File", "GeoPoint", "Array", "Object", "Pointer", "Relation"]
// Then, navigate to your Parse data class, copy paste this code into the console and hit enter
// populating this list will be very tedious if you do not take advantage of an awesome text editor like Sublime Text
var array = [["pooper", "String"], ["poopsToday", "Number"]]
var i = 0
function addColumn()
{
@feighter09
feighter09 / Fonts.swift
Last active Nov 25, 2020
Set global font for iOS app in one place
View Fonts.swift
// MARK: - Swizzling
extension UIFont {
class var defaultFontFamily: String { return "Georgia" }
override public class func initialize()
{
if self == UIFont.self {
swizzleSystemFont()
}
}
@feighter09
feighter09 / changeKeyboardDoneColor.swift
Last active Nov 23, 2019
Change the keyboard "Done" button color to match the rest of your app! This is a total hack though and is likely to get flagged during app review. If so, try obfuscating =)
View changeKeyboardDoneColor.swift
class Utilities {
class func subviewsOfView(view: UIView, withType type: String) -> [UIView]
{
let prefix = "<\(type)"
var subviewArray = view.subviews.flatMap { subview in subviewsOfView(subview, withType: type) }
if view.description.hasPrefix(prefix) {
subviewArray.append(view)
}
View Regex.swift
struct Regex {
let pattern: String
let options: NSRegularExpressionOptions
private var matcher: NSRegularExpression {
return try! NSRegularExpression(pattern: pattern, options: options)
}
init(pattern: String, options: NSRegularExpressionOptions! = nil)
{
@feighter09
feighter09 / FunctionalViewControllers.swift
Last active May 18, 2017
Functional View Controllers from Chris Eidhof's talk @ FunSwiftConf 2015
View FunctionalViewControllers.swift
import UIKit
// MARK: - Building Blocks
struct Screen<A> {
let run: (A -> Void) -> UIViewController
}
extension Screen {
func map<B>(f: A -> B) -> Screen<B>
{
@feighter09
feighter09 / mapFTW.swift
Last active Mar 31, 2016
A Functional Approach to Optionals
View mapFTW.swift
// Scenario: Parsing a JSON object that represents an item in a store
// JSON: { "name": "Bucket", "price": "19.95" }
// The following functions take in a price as a string, and output the result as an Int of cents
// cause I don't trust floating point operations when dealing with other people's money
struct Item {
let name: String
let price: Int
@feighter09
feighter09 / ViewUtilities.swift
Created Apr 28, 2016
IBInspectable UIView Extensions for Fun and Profit
View ViewUtilities.swift
extension UIView {
@IBInspectable var borderColor: UIColor? {
get { return layer.borderColor.map(UIColor.init) }
set { layer.borderColor = newValue?.CGColor }
}
@IBInspectable var borderWidth: CGFloat {
get { return layer.borderWidth }
set { layer.borderWidth = newValue }
}
View MaybeT.hs
-- original
getBody :: ServerPart L.ByteString
parseBody :: FromJSON a => ServerPart (Maybe a)
parseBody = getBody >>= (return . A.decode)
-- attempt
parseBody :: FromJSON a => MaybeT (ServerPartT IO) a
parseBody = lift $ getBody >>= (return . A.decode)
-- Error
View NetworkingEvolution_ViewController_1.swift
import UIKit
import Alamofire
import SwiftyJSON
class ViewController: UIViewController {
convenience init() { self.init(nibName: "ViewController", bundle: nil) }
@IBOutlet weak var label: UILabel!
override func viewDidLoad()
View NetworkingEvolution_Step2_NetworkClient.swift
import Alamofire
import SwiftyJSON
struct NetworkClient {
static func makeRequest(url: String,
params: [String : AnyObject],
callback: (JSON?, ErrorType?) -> Void)
{
request(.POST, url, parameters: params).response { _, _, data, error in
if let jsonData = data where error == nil {
You can’t perform that action at this time.