SPB Git

spb/poche Public

Agent personnel 100 % on-device — SwiftUI + Apple Foundation Models + EventKit + SwiftData. Aucune API, aucun serveur.

Swift 100%
1.7 KB · 58 lines swift
Raw Blame History
1//2//  SharedInbox.swift3//  Poche4//5//  Author:  Simon-Pierre Boucher6//  Contact: contact@spboucher.ai7//8//  Compiled into BOTH the app and the Share Extension: the extension9//  appends, the app drains. Everything stays inside the app group —10//  shared content never touches the network (CLAUDE.md §7).11//1213import Foundation1415struct SharedInboxItem: Codable, Sendable {16    let title: String17    let content: String18    let date: Date19}2021enum SharedInbox {22    static let groupID = "group.ai.spboucher.poche"2324    static var url: URL? {25        FileManager.default26            .containerURL(forSecurityApplicationGroupIdentifier: groupID)?27            .appendingPathComponent("inbox.json")28    }2930    static func append(_ item: SharedInboxItem, at url: URL? = SharedInbox.url) {31        guard let url else { return }32        var items = read(at: url)33        items.append(item)34        let encoder = JSONEncoder()35        encoder.dateEncodingStrategy = .iso860136        if let data = try? encoder.encode(items) {37            try? data.write(to: url, options: .atomic)38        }39    }4041    /// Returns all pending items and empties the inbox.42    static func drain(at url: URL? = SharedInbox.url) -> [SharedInboxItem] {43        guard let url else { return [] }44        let items = read(at: url)45        if !items.isEmpty {46            try? FileManager.default.removeItem(at: url)47        }48        return items49    }5051    private static func read(at url: URL) -> [SharedInboxItem] {52        guard let data = try? Data(contentsOf: url) else { return [] }53        let decoder = JSONDecoder()54        decoder.dateDecodingStrategy = .iso860155        return (try? decoder.decode([SharedInboxItem].self, from: data)) ?? []56    }57}58