Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/SDGGiesbrecht/SDGCornerstone
The Foundation of the SDG Module Family
https://github.com/SDGGiesbrecht/SDGCornerstone
Last synced: 3 months ago
JSON representation
The Foundation of the SDG Module Family
- Host: GitHub
- URL: https://github.com/SDGGiesbrecht/SDGCornerstone
- Owner: SDGGiesbrecht
- License: other
- Created: 2017-04-24T23:06:33.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-07-26T22:00:33.000Z (over 1 year ago)
- Last Synced: 2024-07-17T22:09:14.309Z (4 months ago)
- Language: Swift
- Homepage: https://sdggiesbrecht.github.io/SDGCornerstone/
- Size: 16.4 MB
- Stars: 30
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-system-swift - SDGCornerstone
README
macOS • Windows • Web • Ubuntu • tvOS • iOS • Android • Amazon Linux • watchOS
[Documentation](https://sdggiesbrecht.github.io/SDGCornerstone/%F0%9F%87%A8%F0%9F%87%A6EN)
# SDGCornerstone
SDGCornerstone forms the foundation of the SDG module family; it establishes design patterns and provides general‐use extensions to the [Swift Standard Library](https://developer.apple.com/reference/swift) and [Foundation](https://developer.apple.com/reference/foundation).
> [הִנְנִי יִסַּד בְּצִיּוֹן אָבֶן אֶבֶן בֹּחַן פִּנַּת יִקְרַת מוּסָד מוּסָד׃](https://www.biblegateway.com/passage/?search=Isaiah+28&version=WLC;NIV)
>
> [Behold, I establish in Zion a stone, a tested stone, a precious cornerstone, a sure foundation.](https://www.biblegateway.com/passage/?search=Isaiah+28&version=WLC;NIV)
>
> ―יהוה/Yehova### Features:
- Localization tools compatible with the Swift Package Manager and Linux. (`SDGLocalization`)
- User preferences compatible with Linux. (`PreferenceSet`, `Preference`)
- Platform‐independent access to best‐practice file system locations. (`url(for:in:at:)`)
- Shared instances of value types. (`Shared`)
- Generic pattern matching. (`SearchableCollection`, `Pattern`)
- Customizable randomization. (`SDGRandomization`)
- Arbitrary‐precision arithmetic. (`SDGPrecisionMathematics`)
- A simple API for running shell commands on desktop platforms. (`SDGExternalProcess`)...and much more.
### Example Usage
```swift
// ••••••• Localization •••••••enum ApplicationLocalization: String, Localization {
case english = "en"
case français = "fr"
static let fallbackLocalization = ApplicationLocalization.english
}// Define
let text = UserFacing({ localization in
switch localization {
case .english:
return "Hello, world!"
case .français:
return "Bonjour, le monde !"
}
})// Use
XCTAssertEqual(
text.resolved(),
"Hello, world!"
)// ••••••• Preferences •••••••
let preferences = PreferenceSet.applicationPreferences
// Save
preferences["name"].value.set(to: "John Doe")
// Load
let loaded: String? = preferences["name"].value.as(String.self)XCTAssertEqual(
loaded,
"John Doe"
)// ••••••• File System •••••••
let url = FileManager.default.url(in: .applicationSupport, at: "folder/file.txt")
do {
// Save
try "Contents".save(to: url)
// Load
let loaded = try String(from: url)XCTAssertEqual(
loaded,
"Contents"
)
} catch {
XCTFail(error.localizedDescription)
}// ••••••• Shared Values •••••••
class Owner {
@SharedProperty var property: String = ""
}let originalOwner = Owner()
originalOwner.property = "original"
let anotherOwner = Owner()
anotherOwner.$property = originalOwner.$propertyanotherOwner.property = "changed"
XCTAssertEqual(
originalOwner.property,
"changed"
)// ••••••• Pattern Matching •••••••
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
let patternFirstPart =
[1] // 1
+ ConditionalPattern({ $0.isEven }) // 2
+ ([30, 40] // (∅)
∨ [3, 4]) // 3, 4
let pattern =
patternFirstPart
+ RepetitionPattern(¬[5, 7]) // 5, 6, 7, 8, 9 (...)
+ [10] // 10XCTAssertEqual(
numbers.firstMatch(for: pattern)?.range,
numbers.startIndex.. [Ἄξιος γὰρ ὁ ἐργάτης τοῦ μισθοῦ αὐτοῦ ἐστι.](https://www.biblegateway.com/passage/?search=Luke+10&version=SBLGNT;NIV)
>
> [For the worker is worthy of his wages.](https://www.biblegateway.com/passage/?search=Luke+10&version=SBLGNT;NIV)
>
> ―ישוע/Yeshuʼa