DLDFoundation is a utility Swift package with focused Foundation and standard-library extensions for day-to-day app development.
It includes helpers for:
- Date and time calculations
- JSON encoding/decoding
- URL and file-system scanning
- String transformations and casing
- Collection sorting/grouping utilities
- Numeric conversions and convenience operations
- Bundle/Info.plist accessors
- Swift
6.2(swift-tools-version: 6.2) - macOS
14+ - iOS
17+
CaseAnything(used by string casing helpers)
Add the package in Xcode (File > Add Package Dependencies...) or in Package.swift:
dependencies: [
.package(url: "https://github.com/diliedevs/DLDFoundation.git", branch: "main")
]Then add the product to your target:
.target(
name: "YourTarget",
dependencies: [
.product(name: "DLDFoundation", package: "DLDFoundation")
]
)Import it where needed:
import DLDFoundationlet now = Date.now
let startOfMonth = now.start(of: .month)
let endOfWeek = now.end(of: .week)
let nextDay = now.next(unit: .day)
let hoursUntilTomorrow = now.preciseCount(of: .hour, toDate: nextDay)
let changedYear = now.changing([.year: 2030])
let oneAndHalfDays = 36.hours.count(unit: .day) // 1.5struct Payload: Codable {
let id: Int
let title: String
}
let payload = Payload(id: 1, title: "Hello")
let data = try Data.encodedJSON(
payload,
using: JSONEncoder(prettyPrinted: true, sortedKeys: true)
)
let decoded: Payload = try data.decodeJSON()let root = URL(filePath: "/Users/me/Documents")
if root.exists, root.isDirectory {
let shallow = try root.quickScan(includeHidden: false)
let deep = try root.recursiveScan(relativeURLs: false, includeHidden: true)
print(shallow.count, deep.count)
}let items = [URLQueryItem]([
"q": "swift",
"page": 1
])
let sorted = items.sortedByName()
let query = sorted["q"] // "swift"struct User {
let id: Int
let name: String
}
let users = [
User(id: 2, name: "B"),
User(id: 1, name: "A")
]
let sorted = users.sorted(by: \.id)
let grouped = users.grouped(by: \.name)
let values = [1, 2, 2, 3].uniqued() // order is not guaranteedlet title = "hello world"
title.camelCased() // "helloWorld"
title.pascalCased() // "HelloWorld"
title.kebabCased() // "hello-world"
title.snakeCased() // "hello_world"
title.constantCased() // "HELLO_WORLD"Date,TimeInterval,Calendar.Component(CalUnit),LocaleURL,URLComponents,URLQueryItem,FileManagerStringSequence,Collection,Array,Set,DictionaryBinaryInteger,BinaryFloatingPoint,Numeric,BoolOptional,Comparable,BundleJSONEncoder,JSONDecoder,DataNSSortDescriptor(Sortertypealias)- Model aliases:
Model,ModelEnum
Run the test suite:
swift testCurrent tests cover JSON helpers, URL/file scanning helpers, and date calculations.
DLDFoundation is available under the MIT license, which permits commercial use, modification, distribution, and private use. See the LICENSE file for more info.
