Cosmic Sdk Swift

screenshot of Cosmic Sdk Swift
cosmic

A pure Swift interpretation of the Cosmic JavaScript SDK for use in Swift and SwiftUI projects.

Overview

The CosmicSDKSwift is a pure Swift interpretation of the Cosmic SDK, designed for use in Swift and SwiftUI projects. Inspired by the JavaScript SDK and Adam Rushy's OpenAISwift, this project aims to provide a smart SDK that closely mirrors the functionality of the JavaScript SDK while adhering to common Swift conventions. Cosmic is a headless CMS (content management system) that offers a web dashboard for creating content and an API toolkit for delivering content to websites and applications. The SDK allows users to create their own state to hold results, map variables to arrays of objects, and perform various operations such as finding, inserting, updating, and deleting objects.

Features

  • Swift Package Manager: Integration of the SDK is made easy through Swift Package Manager.
  • API Access Keys: Users can obtain their API access keys from the Cosmic dashboard.
  • Find Objects: Users can find objects using optional parameters such as limit, sorting, and status.
  • Insert Objects: The insertOne() method allows users to add a new object to their Cosmic Bucket.
  • Update Objects: The updateOne() method enables users to update an object's metadata by providing a metadata dictionary with key-value pairs.
  • Delete Objects: Users can delete objects by passing the required "id" parameter to the API.

Usage

To use the SDK, refer to the JavaScript implementation for a complete list of available methods. Note that the Swift version may not be at feature parity or feature complete. However, the following methods are currently available:

  • Find: Use the find() method with optional parameters such as props, limit, sorting, and status to retrieve objects.
  • Find One: To initialize a single object with a specific type, mark it as optional and handle the optionality accordingly.
  • Insert One: The insertOne() method adds a new object to your Cosmic Bucket. Use it for adding an object to an existing object type.
  • Update One: When using updateOne(), users can update an object's metadata by passing an optional metadata dictionary with key-value pairs for title, content, metadata, and status.
  • Delete One: Depending on your data handling method, ensure that the "id" parameter is included for deleting objects through the API.

Summary

The CosmicSDKSwift is a pure Swift SDK that provides functionality for integrating Cosmic, a headless CMS, into Swift and SwiftUI projects. Through the SDK, users can perform various operations such as finding, inserting, updating, and deleting objects within their Cosmic Buckets. The SDK can be easily integrated using the Swift Package Manager, and API access keys can be obtained from the Cosmic dashboard. While the Swift version may not be fully feature complete, it offers key features such as finding objects with optional parameters, inserting and updating objects, and deleting objects with the required "id" parameter.

cosmic
Cosmic

Cosmic is a headless CMS that enables developers to build websites and applications using any tech stack. It features a user-friendly dashboard for managing content, powerful API for retrieving data, and easy integration with popular frontend frameworks and tools.