This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIView { | |
func findSubview(where matches: (UIView) -> Bool) -> UIView? { | |
for subview in subviews { | |
if matches(subview) { | |
return subview | |
} else if let match = subview.findSubview(where: matches) { | |
return match |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User { | |
static let URL_SAVE_TEAM = URL(string: "http://localhost/test/login_mobile.php")! | |
func login(email: String, password: String, completion: @escaping (String?)->()) { | |
var request = URLRequest(url: User.URL_SAVE_TEAM) | |
request.httpMethod = "POST" | |
let postParameters = "email=\(email)&password=\(password)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foudnation | |
extension Dictionary where Key: AnyHashable, Value: AnyHashable { | |
var queryString: String? { | |
var output: String = "" | |
var i = 0 | |
for (key, i) in self.keys.enumerate() { | |
output += prefix + "\(key)=\(self[value])" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// An NSOperation subclass with utilities for creating long-running operations or | |
/// operations that must pause and wait for some result, as well as a concise API | |
/// to make them easy to create, configure and add to background and main queues. | |
class Operation: NSOperation { | |
/// Shared background queue | |
static let backgroundQueue: NSOperationQueue = { | |
var queue = NSOperationQueue() | |
queue.maxConcurrentOperationCount = 5 | |
return queue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Some extensions with overloaded operators for easily adding and removing | |
/// objects to sets when working with CoreData | |
import Foundation | |
import CoreData | |
protocol ManagedSet { | |
var allObjects: [AnyObject] { get } | |
init( array: [AnyObject] ) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Some short hand GCD to keep code cleaner | |
func dispatch_after( delay:Double, closure:()->() ) { | |
dispatch_after( | |
dispatch_time( | |
DISPATCH_TIME_NOW, | |
Int64(delay * Double(NSEC_PER_SEC)) | |
), | |
dispatch_get_main_queue(), closure) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func parse( data: NSData ) { | |
var error: NSError? = nil | |
switch NSJSONSerialization.JSONObjectWithData( data, options: nil, error: &error ) { | |
case .Some(let dictionary as NSDictionary): | |
println( "JSON contained dictionary: \(dictionary)" ) | |
case .Some(let array as NSArray): | |
println( "JSON Contained array: \(array)" ) | |
default: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generates various types of random values | |
// | |
// Created by Patrick Lynch on 6/30/15. | |
// Copyright © 2015 Patrick Lynch. All rights reserved. | |
import Foundation | |
struct Random { | |
// Designed for you to swap out for any other core random function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The 6 ways to uwnrap optionals in Swift 2.0 | |
// | |
// Created by Patrick Lynch on 6/28/15. | |
// Copyright © 2015 Patrick Lynch. All rights reserved. | |
import Foundation | |
// 1. Force Unwrapping | |
// 2. Optional Binding | |
// 3. Optional Chaining |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A quick way to set up use of responder chain with a bit more type safety | |
// | |
// Created by Patrick Lynch on 6/28/15. | |
// Copyright © 2015 Patrick Lynch. All rights reserved. | |
import UIKit | |
protocol Responder { | |
func targetForAction<T, U: RawRepresentable where U.RawValue == Selector>( action: U, withSender sender: AnyObject?) -> T | |
} |
NewerOlder