Skip to content

Instantly share code, notes, and snippets.

Alex Curylo alexcurylo

View GitHub Profile
@alexcurylo
alexcurylo / StandOnGuard.swift
Created Jun 8, 2016
Guard failure diagnosis
View StandOnGuard.swift
guard let keypath = dictionary["field"] as? String,
let rule = dictionary["rule"] as? String,
let comparator = FormFieldDisplayRuleComparator(rawValue: rule),
let value = dictionary["value"]
else
{
return nil
}
View SwiftyInitialization.swift
class SomeViewController: UIViewController {
private typealias My = SomeViewController
private let videoPlayer: AVPlayer
private let videoPlayerLayer: AVPlayerLayer
override init(nibName: String?, bundle nibBundle: NSBundle?) {
(videoPlayer, videoPlayerLayer) = My.commonInit()
View acknowledge.swift
#!/usr/bin/env xcrun swift -F Carthage/Build/Mac
import Foundation
import Markingbird
protocol Streamable {
var title: String { get }
var body: String { get }
}
View TextFieldMaxLengths.swift
import UIKit
// 1
private var maxLengths = [UITextField: Int]()
// 2
extension UITextField {
// 3
@IBInspectable var maxLength: Int {
@alexcurylo
alexcurylo / PatternMatching.swift
Last active May 17, 2016
From Crunchy Development's Pattern Matching series
View PatternMatching.swift
enum Media {
case Book(title: String, author: String, year: Int)
case Movie(title: String, director: String, year: Int)
case WebSite(urlString: String)
}
let mediaList: [Media] = [
.Book(title: "Harry Potter and the Philosopher's Stone", author: "J.K. Rowling", year: 1997),
.Movie(title: "Harry Potter and the Philosopher's Stone", director: "Chris Columbus", year: 2001),
.Book(title: "Harry Potter and the Chamber of Secrets", author: "J.K. Rowling", year: 1999),
@alexcurylo
alexcurylo / singleton.swift
Last active May 8, 2016
Correct Swift Singleton
View singleton.swift
class TheOneAndOnlyKraken {
static let sharedInstance = TheOneAndOnlyKraken()
}
View gist:e363411537dfe3aeb2ba
+ (UIImage *)chevronImageWithColor:(UIColor *)color
{
NSArray *asciiRep =
@[
@"· · · · · · · · · · · ·",
@"· · · 1 2 · · · · · · ·",
@"· · · A # # · · · · · ·",
@"· · · · # # # · · · · ·",
@"· · · · · # # # · · · ·",
@alexcurylo
alexcurylo / ThreadsafeDF.m
Created Feb 16, 2015
Threadsafe Date Formatting
View ThreadsafeDF.m
+ (NSDateFormatter *)dateReader
{
NSMutableDictionary *dictionary = [[NSThread currentThread] threadDictionary];
NSDateFormatter *dateReader = [dictionary objectForKey:@"SCDateReader"];
if (!dateReader)
{
dateReader = [[[NSDateFormatter alloc] init] autorelease];
dateReader.locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease];
dateReader.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
dateReader.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss Z";
@alexcurylo
alexcurylo / 0_reuse_code.js
Last active Aug 29, 2015
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
You can’t perform that action at this time.