Skip to main content

Core API overview

MatrixSwiftBaseCore ships Foundation-only utilities. Import once and reach for the relevant module.

import MatrixSwiftBaseCore

Full type signatures will live in the DocC reference once that lands (#10). This page is the narrative overview with code samples.

Helpers​

Stateless public final class FooHelper containers with static methods.

HelperPurpose
AsyncHelpersCommon async / await patterns
BundleHelperApp / framework bundle introspection
CoreDataHelperLightweight Core Data setup helpers
CryptoHelperHashing, key derivation (CryptoKit)
CurrencyHelperCurrency formatting via NumberFormatter
DateHelperDate construction, formatting, arithmetic
DoubleHelperRounding, formatting, conversions
EmojiHelperEmoji utilities
EnvHelperRead environment variables / process info
FaceIdHelperBiometric availability checks
FunctionHelperDebounce / throttle / memoize-style wrappers
GeometryHelperGeometric calculations (no UIKit)
JsonHelperJSON encode/decode convenience
MathHelperclamp, lerp, common math
MimeTypeHelperFilename ↔ MIME type via UniformTypeIdentifiers
RandomHelperRandom numbers, strings, picks
RegexHelperRegex compile-and-test helpers
SleepHelperSleep in ms / seconds (async-safe)
SoundHelperAudio file utilities
StringHelperCommon string transforms
ThreadHelperThread / queue introspection
UnitHelperUnit conversions

Example​

let clamped = MathHelper.clamp(150, min: 0, max: 100) // 100
try await SleepHelper.milliseconds(250)
let token = RandomHelper.string(length: 32)
let mime = MimeTypeHelper.mimeType(forFilename: "doc.pdf") // "application/pdf"

Extensions​

Drop-in additions to Foundation types.

FileWhat it adds
ArrayExtchunked(into:), subscript(safe:), etc.
BoolExtDisplay / negation helpers
DateExtComponent access, formatting shortcuts
DictionaryExtMerge, transform helpers
SetExttoggle(_:), set algebra sugar
URLExtQuery-item helpers, common transforms

Example​

let chunks = [1, 2, 3, 4, 5].chunked(into: 2) // [[1,2],[3,4],[5]]
let safe = ["a", "b"][safe: 5] // nil

var set: Set = [1, 2]
set.toggle(3) // [1, 2, 3]
set.toggle(1) // [2, 3]

Networking​

Modern async/await HTTP client built on URLSession.

TypePurpose
APIClientSend Endpoint requests, decode responses
EndpointType-safe request description (path, method, headers, body)
HTTPMethodGET / POST / PUT / PATCH / DELETE / …
RequestBodyEmpty / raw data / JSON / form payloads
NetworkErrorTyped errors (no Error casts at call site)

Example​

import Foundation
import MatrixSwiftBaseCore

struct User: Decodable { let id: Int; let name: String }

// `Endpoint` is a protocol: conform a type (often an enum) to it.
// Only `path` is required; `method` defaults to `.get`.
enum UsersAPI: Endpoint {
case me
case rename(String)

var path: String {
switch self {
case .me: return "/users/me"
case .rename: return "/users/me/name"
}
}
var method: HTTPMethod {
switch self {
case .me: return .get
case .rename: return .patch
}
}
var body: RequestBody {
switch self {
case .me: return .empty
case .rename(let name): return .json(["name": name])
}
}
}

let client = APIClient(baseURL: URL(string: "https://api.example.com")!)
let user = try await client.send(UsersAPI.me, as: User.self)

Retry policy is on the roadmap (TODOS.md).

Concurrency​

TypePurpose
IntervalHelperRepeating timer wrappers compatible with structured concurrency

Errors / Logging​

TypePurpose
AppErrorTyped application-level error enum
AppLoggeros.Logger wrapper with category + level helpers

Managers​

Stateful objects that aren't UI but still hold long-lived state.

ManagerPurpose
KeychainManagerSave / load / delete to the system keychain
LocationManagerCLLocationManager wrapper

Models​

Value-typed enums / structs used across the library.

ModelPurpose
ImageFileTypes.jpg / .png / .heic / etc.
LocalNotificationNotification payload struct
SoundFileTypes.mp3 / .wav / .caf / etc.
SystemThemes.light / .dark / .system

Validations​

TypePurpose
ValidationsEmail / phone / URL / general string validators. Will be expanded into a Validator<T> protocol layer per TODOS.md.