Skip to content

Instantly share code, notes, and snippets.

View brettohland's full-sized avatar

brett ohland brettohland

View GitHub Profile
@brettohland
brettohland / 1.README.md
Last active October 23, 2023 20:47
ISBN example with FormatStyle, AttributedStringFormatStyle, ParseableFormatStyle conformance.
View 1.README.md

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

ko-fi

@brettohland
brettohland / 1.0 README.md
Last active July 21, 2023 17:09
ParseableFormatStyle Examples
View iOS-16-FormatStyle.swift
import Foundation
// MARK: - URL
// https://developer.apple.com/documentation/foundation/formatstyle/4013379-url
let appleURL = URL(string: "https://apple.com")!
appleURL.formatted() // "https://apple.com"
appleURL.formatted(.url) // "https://apple.com"
appleURL.formatted(.url.locale(Locale(identifier: "fr_FR"))) // "https://apple.com"
@brettohland
brettohland / 1.0 FormatStyle in Excruciating Detail.md
Last active November 28, 2023 03:37
FormatStyle in Excruciating Detail
View 1.0 FormatStyle in Excruciating Detail.md
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
brettohland / dates.swift
Last active March 12, 2022 14:49
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 = Pathname.new(root)
podfile = root + '/Podfile.lock'
View keybase.md

Keybase proof

I hereby claim:

  • I am brettohland on github.
  • I am bretto (https://keybase.io/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: