Skip to content

Instantly share code, notes, and snippets.

@nicklockwood
nicklockwood / OSKit.swift
Created January 28, 2023 11:32
A lightweight approach to writing cross-platform code in SwiftUI without a lot of conditional compilation blocks
import SwiftUI
enum OSDocumentError: Error {
case unknownFileFormat
}
#if canImport(UIKit)
import UIKit

Modules, Errors and Coupling

Suppose you have a few modules in an application which needs to request and parse data from a JSON api:

  • Http
  • Json parsing
  • Business logic, something to do with Images

Each of these can fail in their own way:

@chriseidhof
chriseidhof / routes.swift
Created August 17, 2014 21:04
Type-safe routes in Swift
//
// main.swift
// Routes
//
// Created by Chris Eidhof on 17/08/14.
// Copyright (c) 2014 Chris Eidhof. All rights reserved.
//
import Foundation