Skip to content

Instantly share code, notes, and snippets.

View theisegeberg's full-sized avatar

Theis Egeberg theisegeberg

View GitHub Profile
@theisegeberg
theisegeberg / SharedState.swift
Created January 14, 2024 18:27
Composable Architecture shared state
import Foundation
import SwiftUI
import ComposableArchitecture
@Reducer
struct Denmark {
@Reducer
struct Destination {
@theisegeberg
theisegeberg / LoadUserDefaultsManually.swift
Created February 9, 2022 06:59
A brute force method of getting UserDefault values.
func getUserDefaultsValueFromFile<T>(forKey key:String, type:T.Type) -> T? {
guard let bundleIdentifier = Bundle.main.bundleIdentifier else {
return nil
}
guard let libraryUrl = FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask).first else {
return nil
}
let userDefaultsUrl = libraryUrl.appendingPathComponent("Preferences").appendingPathComponent(bundleIdentifier).appendingPathExtension("plist")
guard FileManager.default.fileExists(atPath: userDefaultsUrl.path) else {
return nil
@theisegeberg
theisegeberg / ContentView.swift
Created March 22, 2020 17:45
MacOS combine swiftui example
import SwiftUI
import Combine
struct Todo:Codable {
let userId:Int
let id:Int
let title:String
let completed:Bool
}
@theisegeberg
theisegeberg / MCSessionAdapter.swift
Last active December 29, 2021 17:00
MultiPeerConnectivity example (tested working in iOS 12, device + simulator)
import Foundation
import MultipeerConnectivity
class MCSessionAdapter:NSObject,MCSessionDelegate {
var session:MCSession?
weak var delegate:PeerSessionDelegate?
func setSession(_ session:MCSession) {
self.session = session