{"id":32150876,"url":"https://github.com/contentstack/contentstack-utils-swift","last_synced_at":"2026-04-06T11:04:00.092Z","repository":{"id":48040542,"uuid":"299595783","full_name":"contentstack/contentstack-utils-swift","owner":"contentstack","description":"Contentstack Utils SDK for JSON RTE and RTE content","archived":false,"fork":false,"pushed_at":"2025-09-08T16:51:16.000Z","size":312,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-11-18T09:25:44.515Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/contentstack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-09-29T11:28:30.000Z","updated_at":"2025-09-08T16:51:20.000Z","dependencies_parsed_at":"2023-11-16T10:24:59.200Z","dependency_job_id":"d31f9b5f-1047-4703-9635-088d8986ad81","html_url":"https://github.com/contentstack/contentstack-utils-swift","commit_stats":{"total_commits":55,"total_committers":4,"mean_commits":13.75,"dds":"0.36363636363636365","last_synced_commit":"623a98a5cb1a18bfa340e02175cde7d5ce7a4f8e"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/contentstack/contentstack-utils-swift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/contentstack%2Fcontentstack-utils-swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/contentstack%2Fcontentstack-utils-swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/contentstack%2Fcontentstack-utils-swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/contentstack%2Fcontentstack-utils-swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/contentstack","download_url":"https://codeload.github.com/contentstack/contentstack-utils-swift/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/contentstack%2Fcontentstack-utils-swift/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29574747,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-18T08:38:15.585Z","status":"ssl_error","status_checked_at":"2026-02-18T08:38:14.917Z","response_time":162,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-21T10:26:57.406Z","updated_at":"2026-04-06T11:04:00.084Z","avatar_url":"https://github.com/contentstack.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ![Contentstack](https://www.contentstack.com/docs/static/images/contentstack.png)\n\n# Contentstack Swift SDK\n![ContentstackUtils CI](https://github.com/contentstack/contentstack-utils-swift/workflows/ContentstackUtils%20CI/badge.svg)\n\nContentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. Build your application frontend, and Contentstack will take care of the rest. [Read More](https://www.contentstack.com/).\n\nContentstack provides iOS SDK to build application on top of iOS. Given below is the detailed guide and helpful resources to get started with our iOS SDK.\n\n\n### Prerequisite\nLatest Xcode and Mac OS X\n\n### Setup and Installation\nTo use this SDK on iOS platform, you will have to install the SDK according to the steps given below.\n\n##### CocoaPods\nAdd the following to your Podfile:\n\n    use_frameworks!\n    pod 'ContentstackUtils', '~\u003e 1.3.1'\n    \n#### Swift Package Manager\n1. Installing libxml2 to your computer:\n\n    ```bash\n    // macOS: For xcode 11.3 and earlier, the following settings are required.\n    $ brew install libxml2\n    $ brew link --force libxml2\n\n    // Linux(Ubuntu):\n    $ sudo apt-get install libxml2-dev\n    ```\n\n2. Add the following to your `Package.swift`:\n\n    ```swift\n    // swift-tools-version:5.0\n    import PackageDescription\n\n    let package = Package(\n        name: \"YourProject\",\n        dependencies: [\n            .package(url: \"https://github.com/tid-kijyun/ContentstackUtils.git\", from: \"1.5.0\"),\n        ],\n        targets: [\n            .target(\n                name: \"YourTarget\",\n                dependencies: [\"ContentstackUtils\"]),\n        ]\n    )\n    ```\n\n    ```bash\n    $ swift build\n    ```\n\n*Note: When a build error occurs, please try run the following command:*\n\n    // Linux(Ubuntu)\n    $ sudo apt-get install pkg-config\n\n#### Manual Installation\n1. Add Contentstack Utils file to your project:\n    [ContentstackUtils](Sources/ContentstackUtils)  \n1. Add Kanna files to your project:  \n      [Kanna](Sources/Kanna)  \n      [Modules](Modules)\n1. In the target settings add `$(SDKROOT)/usr/include/libxml2` to the `Search Paths \u003e Header Search Paths` field\n1. In the target settings add `$(SRCROOT)/Modules` to the `Swift Compiler - Search Paths \u003e Import Paths` field\n\n\u003e Note: If you are using Contentstack Swift SDK in your project, the ContentstackUtils file is already imported.\n\n## Usage\n\nLet’s learn how you can use Utils SDK to render embedded items.\n\n### Create Render Option\n\nTo render embedded items on the front-end, create a class implementing Option protocol,  and define the UI elements you want to show in the front-end of your website, as shown in the example below:\n```swift\nimport Foundation  \nimport ContentstackUtils  \nclass  CustomRenderOption: Option {  \n\noverride func renderMark(markType: MarkType, text: String) -\u003e String {\n    switch markType {\n    case .bold:\n        return \"\u003cb\u003e\\(text)\u003c/b\u003e\"\n    default:\n        return super.renderMark(markType: markType, text: text)\n    }\n}\n\noverride func renderNode(nodeType: String, node: Node, next: (([Node]) -\u003e String)) -\u003e String {\n    switch nodeType {\n    case \"p\":\n        return \"\u003cp class='class-id'\u003e\\(next(node.children))\u003c/p\u003e\"\n    case \"h1\":\n        return \"\u003ch1 class='class-id'\u003e\\(next(node.children))\u003c/h1\u003e\"\n    default:\n        return super.renderNode(nodeType: nodeType, node: node, next: next)\n    }\n}\n  \nfunc renderOptions(embeddedObject: EmbeddedObject, metadata: Metadata) -\u003e String? {\n      switch metadata.styleType {\n      case .block:\n          if metadata.contentTypeUid == \"product\" {\n              if let product = embeddedObject as? Product {\n                  return \"\"\"\n                      \u003cdiv\u003e\n                      \u003ch2 \u003e\\(product.title)\u003c/h2\u003e\n                      \u003cimg src=\\(product.product_image.url) alt=\\(product.product_image.title)/\u003e\n                      \u003cp\u003e\\(product.price)\u003c/p\u003e\n                      \u003c/div\u003e\n                  \"\"\"\n              }\n          }else {\n              if let entry = embeddedObject as? Entry {\n                  return \"\"\"\n                      \u003cdiv\u003e\n                      \u003ch2\u003e\\(entry.title)\u003c/h2\u003e\n                      \u003cp\u003e\\(entry.description)\u003c/p\u003e\n                      \u003c/div\u003e\n                      \"\"\"\n              }\n          }\n      default:\n          return super.renderOptions(embeddedObject: embeddedObject, metadata: metadata)\n      }\n}\n```\n\n## Basic Queries\nContentstack Utils SDK lets you interact with the Content Delivery APIs and retrieve embedded items from the RTE field of an entry.\n\n### Fetch Embedded Item(s) from a Single Entry\n#### Render HTML RTE Embedded object\nTo get an embedded items of a single entry, you need to provide the stack API key, environment name, delivery token, content type and entry UID. Then, use the `ContentstackUtils.render` functions as shown below:\n```swift\nimport ContentstackUtils  \n\nlet stack:Stack = Contentstack.stack(apiKey: API_KEY, deliveryToken: DELIVERY_TOKEN, environment: ENVIRONMENT)  \n\nstack.contentType(uid: contentTypeUID)\n     .entry(uid: entryUID)\n     .include(.embeddedItems)  \n     .fetch { (result: Result\u003cEntryModel, Error\u003e, response: ResponseType) in  \n        switch result {  \n            case .success(let model):\n                ContentstackUtils.render(content: model.richTextContent, Option(entry: model))  \n            case .failure(let error):  \n                //Error Message  \n        }  \n    }\n```\n\n#### Render Supercharged RTE contents\nTo get a single entry, you need to provide the stack API key, environment name, delivery token, content type and entry UID. Then, use `ContentstackUtils.jsonToHtml` function as shown below:\n```swift\nimport ContentstackUtils  \n\nlet stack:Stack = Contentstack.stack(apiKey: API_KEY, deliveryToken: DELIVERY_TOKEN, environment: ENVIRONMENT)  \n\nstack.contentType(uid: contentTypeUID)\n     .entry(uid: entryUID)\n     .include(.embeddedItems)  \n     .fetch { (result: Result\u003cEntryModel, Error\u003e, response: ResponseType) in  \n        switch result {  \n            case .success(let model):\n                ContentstackUtils.jsonToHtml(content: model.richTextContent, Option(entry: model))  \n            case .failure(let error):  \n                //Error Message  \n        }  \n    }\n```\n\u003e Node: Supercharged RTE also supports Embedded items to get all embedded items while fetching entry use `includeEmbeddedItems` function.\n\n### Fetch Embedded Item(s) from Multiple Entries\n#### Render HTML RTE Embedded object\nTo get embedded items from multiple entries, you need to provide the stack API key, environment name, delivery token, and content type UID. Then, use the `ContentstackUtils.render` functions as shown below:\n```\nimport ContentstackUtils  \n\nlet stack = Contentstack.stack(apiKey: apiKey,  \ndeliveryToken: deliveryToken,  \nenvironment: environment)  \n  \nstack.contentType(uid: contentTypeUID)\n     .entry()\n     .query()\n     .include(.embeddedItems)\n     .find { (result: Result\u003cContentstackResponse\u003cEntryModel\u003e, Error\u003e, response: ResponseType) in  \n        switch result {  \n            case .success(let contentstackResponse):  \n                for item in contentstackResponse.items {  \n                    ContentstackUtils.render(content: item.richTextContent, CustomRenderOption(entry: item))  \n                }  \n            case .failure(let error):  \n                //Error Message  \n        }  \n    }\n```\n\n#### Render Supercharged RTE contents\nTo get a Multiple entry, you need to provide the stack API key, environment name, delivery token, and content type UID. Then, use `Contentstack.Utils.jsonToHtml` function as shown below:\n```swift\nimport ContentstackUtils  \n\nlet stack:Stack = Contentstack.stack(apiKey: API_KEY, deliveryToken: DELIVERY_TOKEN, environment: ENVIRONMENT)  \n\nstack.contentType(uid: contentTypeUID)\n     .entry()\n     .query()\n     .include(.embeddedItems)\n     .find { (result: Result\u003cEntryModel, Error\u003e, response: ResponseType) in  \n        switch result {  \n            case .success(let model):\n                for item in contentstackResponse.items {  \n                    ContentstackUtils.jsonToHtml(content: item.richTextContent, CustomRenderOption(entry: item))  \n                }\n            case .failure(let error):  \n                //Error Message  \n        }  \n    }\n```\n\n### GraphQL implementation\nAfter fetching the entries from the content type pass the JSON RTE to `ContentstackUtils.GQL.jsonToHtml` function as shown below:\n\n```swift\nimport ContentstackUtils  \nimport Apollo\n...\nlet graphQLClient: ApolloClient\n...\n\ngraphQLClient.fetch (query: ProductsQuery(), cachePolicy: CachePolicy.fetchIgnoringCacheData, queue: DispatchQueue.main) {[weak self] (result: Result\u003cGraphQLResult\u003cProductsQuery.Data\u003e, Error\u003e) in\n    guard let slf = self else {\n                   return\n               }\n    switch result {\n    case .success(let graphQLResult):\n        guard let data = graphQLResult.data, let products = data.allAbcd?.items else {\n           return\n        }\n\n        for product in products {\n            if let rte = product.superchargedRte {\n               let result = try? ContentstackUtils.GQL.jsonToHtml(rte: rte.resultMap)\n            }\n        }\n    case .failure(let error):\n      print(\"Failure! Error: \\(error)\")\n    }\n}\n```\n\n### Variant metadata (`data-csvariants`)\n\nTo build the JSON string for the `data-csvariants` HTML attribute from Delivery API entry JSON, use **`ContentstackUtils.getVariantMetadataTags`**. See [Docs/variant-metadata-api.md](Docs/variant-metadata-api.md) for parameters, return values, and migration from the deprecated `getDataCsvariantsAttribute` APIs.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcontentstack%2Fcontentstack-utils-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcontentstack%2Fcontentstack-utils-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcontentstack%2Fcontentstack-utils-swift/lists"}