Skip to content

Instantly share code, notes, and snippets.


brett ohland brettohland

View GitHub Profile
brettohland /
Last active Oct 1, 2022
ISBN example with FormatStyle, AttributedStringFormatStyle, ParseableFormatStyle conformance.

Supporting FormatStyle & ParseableFormatStyle To Your Custom Types

A full example of adding String and AttributedString output to our custom types, as well as adding the ability to parse String values into your custom type.

Read the blog post

See the Xcode Playground


View iOS-16-FormatStyle.swift
import Foundation
// MARK: - URL
let appleURL = URL(string: "")!
appleURL.formatted() // ""
appleURL.formatted(.url) // ""
appleURL.formatted(.url.locale(Locale(identifier: "fr_FR"))) // ""
View 1.0 FormatStyle in Excruciating
View custom-formatstyle.swift
struct ToYen: FormatStyle {
typealias FormatInput = Int
typealias FormatOutput = String
func format(_ value: Int) -> String {
Decimal(value * 100).formatted(.currency(code: "jpy"))
extension FormatStyle where Self == ToYen {
brettohland / dates.swift
Last active Mar 12, 2022
Date.FormatStyle Examples and Usage
View dates.swift
import SwiftUI
import UIKit
// MARK: - Setup
let twosdayDateComponents = DateComponents(
year: 2022,
month: 2,
day: 22,
hour: 2,
View nuke-pods.rb
#! /usr/bin/env ruby
require 'fileutils'
require 'pathname'
#Remove the \n character at the end of the path returned
root = %x(git rev-parse --show-toplevel).chomp
root_path =
podfile = root + '/Podfile.lock'

Keybase proof

I hereby claim:

  • I am brettohland on github.
  • I am bretto ( on keybase.
  • I have a public key whose fingerprint is 424B 5733 C07A DD48 3D7B 8147 1F6B 0BDD 87F4 51F2

To claim this, I am signing this object: