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.
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.
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" |
A collection of all of the various options and styles available to you if you'd like to format data into string on iOS 15.
See every option in detail at fuckingformatstyle.com or goshdarnformatstyle.com.
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 { |
import SwiftUI | |
import UIKit | |
// MARK: - Setup | |
let twosdayDateComponents = DateComponents( | |
year: 2022, | |
month: 2, | |
day: 22, | |
hour: 2, |
#! /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' |
I hereby claim:
To claim this, I am signing this object: