Menu

1 / 2

Deep Dive into SwiftWork (Part 4): Data Layer and Services — SwiftData, State Restore, Markdown Rendering

DEV Community·NEE·7 months ago
#ZfscAh4H
#swiftdata#swift#macos#markdown#session
Reading 0:00
15s threshold

The previous three posts covered how events flow from the SDK to the UI, how the timeline renders, and how tool cards visualize. This final post looks at SwiftWork's infrastructure — how data is stored, how state is restored, how Markdown is rendered, how code is highlighted, and how API keys are managed.

These components are independent, but all essential to making the app usable.

SwiftData Model Layer

SwiftWork uses SwiftData for persistence, registering four models:

// SwiftWorkApp.swift . modelContainer ( for : [ Session . self , Event . self , AppConfiguration . self , PermissionRule . self ])

Enter fullscreen mode

Exit fullscreen mode

Session

@Model final class Session { @Attribute ( . unique ) var id : UUID var title : String var createdAt : Date var updatedAt : Date var workspacePath : String ? @Relationship ( deleteRule : . cascade , inverse : \ Event .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.