Skip to content

Instantly share code, notes, and snippets.

enum DateStride {
case year(Int)
case month(Int)
case day(Int)
var component: Calendar.Component {
switch self {
case .year(_):
return .year
@warren-gavin
warren-gavin / UIFont+TextStyle.swift
Created June 16, 2018 12:22
Get the UIFont.TextStyle that a font was created with
// Fonts can be created with UIFont.preferredFont(forTextStyle:), but there's
// no direct way to find out what textStyle a font was created with.
//
// Requires: Swift 4.2, iOS 11
extension UIFont {
// Can be nil if the font was created using another method other than UIFont.preferredFont(forTextStyle:)
var textStyle: TextStyle? {
guard let styleName = fontDescriptor.fontAttributes[.textStyle] as? String else {
return nil
}

Code snippets for the blog post "The font of all... well, some knowledge"

@warren-gavin
warren-gavin / Touchy Feely.md
Last active February 12, 2017 15:12
Code snippets for blog "Touchy-feely"
import Foundation
import FirebaseDatabase
import AcmeJSONLib
struct Opinion {
let text: String
fileprivate let soapBoxing: Bool
}
// MARK: - Opinions stored in Firebase
@warren-gavin
warren-gavin / mvvm-rrosrws.md
Last active November 5, 2016 15:59
Code snippets for the blog post on MVC-RS

Code snippets for the blog post "A Math-er of fact"