Skip to content

nikolainobadi/NnSwiftDataKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NnSwiftDataKit

NnSwiftDataKit is a Swift package designed to simplify the configuration of SwiftData containers, particularly when working with App Groups. It provides a convenient method to create a SwiftData container with support for Application Groups and user defaults.

Features

  • Configures SwiftData containers for use with App Groups.
  • Ensures the necessary directories are created.
  • Returns both a ModelConfiguration and a UserDefaults instance.

Installation

Add the package to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/nikolainobadi/NnSwiftDataKit", from: "0.5.0")
]

Usage

Importing the Package

import NnSwiftDataKit

Configuring the SwiftData Container

Use the configureSwiftDataContainer function to set up the container and user defaults:

do {
    let (config, defaults) = try configureSwiftDataContainer(appGroupId: "group.com.example.app")
    print("Successfully configured container and user defaults.")
} catch {
    print("Error configuring SwiftData container: \(error)")
}

Error Handling

If the specified App Group cannot be accessed, the function will throw a SwiftDataContextError.noAppGroupAccess error.

Contributing

Any feedback or ideas to enhance NnSwiftDataKit would be well received. Please feel free to open an issue if you'd like to help improve this Swift package.

License

NnSwiftDataKit is licensed under the MIT License. See the LICENSE file for details.

About

Small Package to help instantiate SwiftData for shared database access (using AppGroups)

Topics

Resources

License

Stars

Watchers

Forks

Languages