-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Use
Text.Case
& implement more environments
- Loading branch information
Showing
6 changed files
with
68 additions
and
39 deletions.
There are no files selected for viewing
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
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
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
34 changes: 34 additions & 0 deletions
34
Sources/Luminare/Utilities/Extensions/Text+Extensions.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// Text+Extensions.swift | ||
// Luminare | ||
// | ||
// Created by KrLite on 2024/12/18. | ||
// | ||
|
||
import SwiftUI | ||
|
||
extension Text.Case: Codable { | ||
enum CodingKeys: String, CodingKey { | ||
case rawValue | ||
} | ||
|
||
public init(from decoder: any Decoder) throws { | ||
let values = try decoder.container(keyedBy: CodingKeys.self) | ||
switch try values.decode(String.self, forKey: .rawValue) { | ||
case "uppercase": | ||
self = .uppercase | ||
case "lowercase": | ||
self = .lowercase | ||
default: | ||
throw DecodingError.dataCorrupted(.init( | ||
codingPath: [CodingKeys.rawValue], | ||
debugDescription: "Unknown case" | ||
)) | ||
} | ||
} | ||
|
||
public func encode(to encoder: any Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
try container.encode(self, forKey: .rawValue) | ||
} | ||
} |
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
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