Skip to content

Repository files navigation

CoreKit

CoreKit is a lightweight Swift package that bundles a collection of general-purpose utilities, foundation extensions, and small helper types used across projects. It focuses on the everyday building blocks — string and collection helpers, date formatting, cryptography, error handling, and async testing tools — so you don't have to rewrite them in every app.

Requirements

  • Swift 6.3+
  • A platform that provides Foundation, CryptoKit, and CommonCrypto (iOS, macOS, tvOS, watchOS, visionOS)

Installation

Add CoreKit to your Package.swift:

dependencies:[.package(url:"https://github.com/thomasalbert1993/CoreKit.git", from:"1.0.0")]

Then add it as a dependency of your target:

.target(
name:"MyApp",
dependencies:["CoreKit"])

CoreKit depends on BigInt, which is resolved automatically.

To use it in code:

import CoreKit

Features

Cryptography

AES encryption — AES-CBC with PKCS7 padding, supporting 128-, 192-, and 256-bit keys.

letkey=Data(/* 16, 24, or 32 bytes */)letiv=AESEncryption.generateRandomIV()!
letciphertext=AESEncryption.encrypt(data: plaintext, key: key, iv: iv)letplaintext=AESEncryption.decrypt(data: ciphertext!, key: key, iv: iv)

SHA-256 — hashing for Data and String, returned as a hex string.

"hello".sha256() // "2cf24dba..."
someData.sha256()

Encoding

Base62 — compact, URL-safe encoding for Data, String, and UUID.

UUID().base62Encoded()"hello".base62Encoded()
someData.base62EncodedString()

Hex — hexadecimal representation of Data.

someData.hexString

Dates

  • Date.utcString(timeStyle:) — ISO 8601 UTC serialization (none, second, or microsecond precision).
  • String.toDate() — parse ISO 8601 strings back into Date (second and microsecond precision).
  • MicroSecondISO8601DateFormatter — a formatter that handles microsecond-precise fractional seconds, which the standard ISO8601DateFormatter does not.
  • Date.components(includingTime:in:), Date.slightlyBefore, and Date.slightlyAfter helpers.
letstring=Date().utcString(timeStyle:.microsecond)letdate=try string.toDate()

Semantic versioning

SemanticVersion parses, compares, and prints major.minor.patch versions.

leta=SemanticVersion("1.2.0")!
letb=SemanticVersion(major:1, minor:3, patch:0)
a < b // true
b.literal // "1.3.0"

Error handling

  • The ?! operator throws a given error when the left-hand value is nil.
  • String conforms to Error / LocalizedError for quick debug errors.
  • DebuggableError provides consistent, readable error descriptions (including case name and associated values) in both Debug and Release builds.
letinstance=try repository.fetch(id: id)?!MyError.notFound(id: id)enumAPIError:DebuggableError{case internalError(code:Int)}
// print → "APIError.internalError(502)"

Async testing helpers

Guard asynchronous test code against hangs with a bounded timeout.

tryawaitwithTimeout(2.0){await sut.performWork()}letvalue=tryawaitawaitCompletion{ completion in
legacyAPI.load{completion($0)}}

Foundation extensions

A set of convenience extensions on the standard library and Foundation types:

TypeHighlights
Arraychunked(into:), distinctValues(), randomElements(count:preserveOrder:), remove(_:), removeFirst(while:), IndexSet subscript
CollectionemptyAsNil, plus Identifiable helpers: ids, first(id:), firstIndex(id:), contains(id:)
DictionarymapKeys(_:), compactMapKeys(_:), contains(key:)
Sequencegrouped(by:), sum()
Settoggle(_:), difference(from:), remove(id:)
StringemptyAsNil, trimmed(), removingAccents(), toURL(), uniqueID(withPrefix:), randomUppercasedCharactersAndDigits(length:)
Doublerounded(toDecimals:), hasFractionalPart
ClosedRangeintersects(with:), nullable bounds via the RangeBound protocol

Misc helpers

  • WeakRef<T> — store weak references inside collections.
  • DebugDescription — build readable, consistent description strings for your types (automatically includes id for Identifiable objects).
finalclassSession{}letref=WeakRef(session) // ref.value becomes nil when session is deallocated

Testing

The package ships with a full test suite built on the Swift Testing framework. Run it with:

swift test

License

CoreKit is available under the MIT license. See the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages