Skip to content

diliedevs/DLDFoundation

Repository files navigation

DLDFoundation Logo

Swift Version Apple Platforms Current Tag License type @DiLieDevs on X

DLDFoundation

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

Requirements

  • Swift 6.2 (swift-tools-version: 6.2)
  • macOS 14+
  • iOS 17+

Dependencies

Installation

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 DLDFoundation

Highlights

Date and Time

let 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.5

JSON

struct 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()

URLs and File System

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)
}

Query Items

let items = [URLQueryItem]([
    "q": "swift",
    "page": 1
])

let sorted = items.sortedByName()
let query = sorted["q"] // "swift"

Collections

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 guaranteed

Strings

let title = "hello world"

title.camelCased()     // "helloWorld"
title.pascalCased()    // "HelloWorld"
title.kebabCased()     // "hello-world"
title.snakeCased()     // "hello_world"
title.constantCased()  // "HELLO_WORLD"

API Surface (By Area)

  • Date, TimeInterval, Calendar.Component (CalUnit), Locale
  • URL, URLComponents, URLQueryItem, FileManager
  • String
  • Sequence, Collection, Array, Set, Dictionary
  • BinaryInteger, BinaryFloatingPoint, Numeric, Bool
  • Optional, Comparable, Bundle
  • JSONEncoder, JSONDecoder, Data
  • NSSortDescriptor (Sorter typealias)
  • Model aliases: Model, ModelEnum

Testing

Run the test suite:

swift test

Current tests cover JSON helpers, URL/file scanning helpers, and date calculations.

License

DLDFoundation is available under the MIT license, which permits commercial use, modification, distribution, and private use. See the LICENSE file for more info.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages