This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"basics": { | |
"languages": [ | |
{ | |
"language": "English", | |
"fluency": "C2 Fluent/Native" | |
}, | |
{ | |
"language": "Spanish", | |
"fluency": "C2 Fluent/Native" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct MeasureSizeModifier: ViewModifier { | |
@Binding var size: CGSize | |
func body(content: Content) -> some View { | |
content.background { | |
GeometryReader { geometry in | |
Color.clear | |
.onAppear { size = geometry.size } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public extension String { | |
fileprivate static let unicodeFlagsBase = 0x1F1E6 - UInt32("A") | |
/// Creates a Unicode flag emoji for the given ISO region/country code. | |
/// | |
/// String(flag: "CH") // returns "๐จ๐ญ" | |
/// String(flag: "in") // returns "๐ฎ๐ณ" | |
/// String(flag: "eu") // returns "๐ช๐บ" | |
/// String(flag: "42") // returns nil | |
/// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Allows us to persist any Codable with @AppStorage and @SceneStorage (via a JSON String). | |
public protocol RawCodable { | |
static var emptyJSON: String { get } | |
} | |
public extension RawCodable where Self: Codable { | |
init?(rawValue: String) { | |
guard let data = rawValue.data(using: .utf8), | |
let value = (try? JSONDecoder().decode(Self.self, from: data)) else { return nil } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public struct Backport<Portee> { | |
let portee: Portee | |
} | |
public extension URLSession { | |
var backport: Backport<URLSession> { | |
Backport(portee: self) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prefix operator ^ | |
postfix operator ^ | |
extension URL: ExpressibleByStringLiteral { | |
/// Conveniently initializes a `URL` from a string literal: | |
/// | |
/// let url: URL = "https://www.somewhere.com" | |
public init(stringLiteral value: StringLiteralType) { | |
self.init(string: value)! | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension Calendar { | |
static let gregorian = Calendar(identifier: .gregorian) | |
} | |
extension TimeZone { | |
static let utc = TimeZone(secondsFromGMT: 0) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension String { | |
var flag: String { | |
uppercased().unicodeScalars | |
.filter { (65...90).contains($0.value) } | |
.compactMap { UnicodeScalar(0x1F1E6 - 65 + $0.value) } | |
.map(String.init) | |
.joined() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
If you've ever wished you could calculate or evaluate something inside your #SwiftUI view's body without repeating yourself, try this pseudo-view helper. | |
You can now compute multiple values in tuples, call helper functions or print debug expressions. | |
*/ | |
struct Calculate<Content: View, Value>: View { | |
let calculation: () -> Value | |
let content: (Value) -> Content | |
init( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ContentView: View { | |
let labels = ["First Name", "Last Name", "Street", "City", "Post Code"] | |
@State private var values = Array(repeating: "", count: 5) | |
var body: some View { | |
List(0..<5) { index in | |
FloatingTextField(title: self.labels[index], text: self.$values[index]) | |
}.listStyle(GroupedListStyle()) | |
} | |
} |
NewerOlder