{"id":20607706,"url":"https://github.com/open-feature/swift-sdk","last_synced_at":"2025-04-15T04:02:39.200Z","repository":{"id":190542932,"uuid":"663664209","full_name":"open-feature/swift-sdk","owner":"open-feature","description":"Swift implementation of the OpenFeature SDK for iOS clients","archived":false,"fork":false,"pushed_at":"2025-03-29T03:07:00.000Z","size":102,"stargazers_count":19,"open_issues_count":9,"forks_count":3,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-04-15T04:01:42.108Z","etag":null,"topics":["sdk"],"latest_commit_sha":null,"homepage":"https://openfeature.dev","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/open-feature.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-07T20:31:30.000Z","updated_at":"2025-03-18T03:56:06.000Z","dependencies_parsed_at":"2023-10-13T08:29:05.629Z","dependency_job_id":"7f372ba2-fa7c-468e-ac44-0edd8a08efcd","html_url":"https://github.com/open-feature/swift-sdk","commit_stats":null,"previous_names":["open-feature/swift-sdk"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-feature%2Fswift-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-feature%2Fswift-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-feature%2Fswift-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-feature%2Fswift-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/open-feature","download_url":"https://codeload.github.com/open-feature/swift-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249003949,"owners_count":21196793,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["sdk"],"created_at":"2024-11-16T10:08:22.415Z","updated_at":"2025-04-15T04:02:39.185Z","avatar_url":"https://github.com/open-feature.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- markdownlint-disable MD033 --\u003e\n\u003c!-- x-hide-in-docs-start --\u003e\n\u003cp align=\"center\"\u003e\n  \u003cpicture\u003e\n    \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://raw.githubusercontent.com/open-feature/community/0e23508c163a6a1ac8c0ced3e4bd78faafe627c7/assets/logo/horizontal/white/openfeature-horizontal-white.svg\" /\u003e\n    \u003cimg align=\"center\" alt=\"OpenFeature Logo\" src=\"https://raw.githubusercontent.com/open-feature/community/0e23508c163a6a1ac8c0ced3e4bd78faafe627c7/assets/logo/horizontal/black/openfeature-horizontal-black.svg\" /\u003e\n  \u003c/picture\u003e\n\u003c/p\u003e\n\n\u003ch2 align=\"center\"\u003eOpenFeature iOS SDK\u003c/h2\u003e\n\n\u003c!-- x-hide-in-docs-end --\u003e\n\u003c!-- The 'github-badges' class is used in the docs --\u003e\n\u003cp align=\"center\" class=\"github-badges\"\u003e\n\u003c!-- TODO: update this with the version of the SDK your implementation supports --\u003e\n\n  \u003ca href=\"https://github.com/open-feature/spec/releases/tag/v0.8.0\"\u003e\n    \u003cimg alt=\"Specification\" src=\"https://img.shields.io/static/v1?label=specification\u0026message=v0.8.0\u0026color=yellow\u0026style=for-the-badge\" /\u003e\n  \u003c/a\u003e\n  \u003c!-- x-release-please-start-version --\u003e\n\n  \u003ca href=\"https://github.com/open-feature/swift-sdk/releases/tag/0.3.0\"\u003e\n    \u003cimg alt=\"Release\" src=\"https://img.shields.io/static/v1?label=release\u0026message=v0.3.0\u0026color=blue\u0026style=for-the-badge\" /\u003e\n  \u003c/a\u003e\n\n  \u003c!-- x-release-please-end --\u003e\n  \u003cbr/\u003e\n  \u003cimg alt=\"Status\" src=\"https://img.shields.io/badge/lifecycle-alpha-a0c3d2.svg\" /\u003e\n\u003c/p\u003e\n\u003c!-- x-hide-in-docs-start --\u003e\n\n[OpenFeature](https://openfeature.dev) is an open specification that provides a vendor-agnostic, community-driven API for feature flagging that works with your favorite feature flag management tool or in-house solution.\n\n\u003c!-- x-hide-in-docs-end --\u003e\n## 🚀 Quick start\n\n### Requirements\n\n- The minimum iOS version supported is: `iOS 14`.\n\nNote that this library is intended to be used in a mobile context, and has not been evaluated for use in other type of applications (e.g. server applications, macOS, tvOS, watchOS, etc.).\n\n### Install\n\n#### Xcode Dependencies\n\nYou have two options, both start from File \u003e Add Packages... in the code menu.\n\nFirst, ensure you have your GitHub account added as an option (+ \u003e Add Source Control Account...). You will need to create a [Personal Access Token](https://github.com/settings/tokens) with the permissions defined in the Xcode interface.\n\n1. Add as a remote repository\n    * Search for `git@github.com:open-feature/swift-sdk.git` and click \"Add Package\"\n2. Clone the repository locally\n    * Clone locally using your preferred method\n    * Use the \"Add Local...\" button to select the local folder\n\n**Note:** Option 2 is only recommended if you are making changes to the client SDK.\n\n#### Swift Package Manager\n\nIf you manage dependencies through SPM, in the dependencies section of Package.swift add:\n\n\u003c!---x-release-please-start-version--\u003e\n```swift\n.package(url: \"git@github.com:open-feature/swift-sdk.git\", from: \"0.3.0\")\n```\n\u003c!---x-release-please-end--\u003e\n\nand in the target dependencies section add:\n```swift\n.product(name: \"OpenFeature\", package: \"swift-sdk\"),\n```\n\n### Usage\n\n```swift\nimport OpenFeature\n\nTask {\n    let provider = CustomProvider()\n    // configure a provider, wait for it to complete its initialization tasks\n    await OpenFeatureAPI.shared.setProviderAndWait(provider: provider)\n\n    // get a bool flag value\n    let client = OpenFeatureAPI.shared.getClient()\n    let flagValue = client.getBooleanValue(key: \"boolFlag\", defaultValue: false)\n}\n```\n\n## 🌟 Features\n\n\n| Status  | Features                        | Description                                                                                                                        |\n| ------  | ------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |\n| ✅      | [Providers](#providers)         | Integrate with a commercial, open source, or in-house feature management tool.                                                     |\n| ✅      | [Targeting](#targeting)         | Contextually-aware flag evaluation using [evaluation context](https://openfeature.dev/docs/reference/concepts/evaluation-context). |\n| ✅      | [Hooks](#hooks)                 | Add functionality to various stages of the flag evaluation life-cycle.                                                             |\n| ❌      | [Tracking](#tracking)           | Associate user actions with feature flag evaluations.                                                                              |\n| ❌      | [Logging](#logging)             | Integrate with popular logging packages.                                                                                           |\n| ❌      | [Named clients](#named-clients) | Utilize multiple providers in a single application.                                                                                |\n| ✅      | [Eventing](#eventing)           | React to state changes in the provider or flag management system.                                                                  |\n| ❌      | [Shutdown](#shutdown)           | Gracefully clean up a provider during application shutdown.                                                                        |\n| ✅      | [Extending](#extending)         | Extend OpenFeature with custom providers and hooks.                                                                                |\n\n\u003csub\u003eImplemented: ✅ | In-progress: ⚠️ | Not implemented yet: ❌\u003c/sub\u003e\n\n### Providers\n\n[Providers](https://openfeature.dev/docs/reference/concepts/provider) are an abstraction between a flag management system and the OpenFeature SDK.\nLook [here](https://openfeature.dev/ecosystem?instant_search%5BrefinementList%5D%5Btype%5D%5B0%5D=Provider\u0026instant_search%5BrefinementList%5D%5Btechnology%5D%5B0%5D=Swift) for a complete list of available providers.\nIf the provider you're looking for hasn't been created yet, see the [develop a provider](#develop-a-provider) section to learn how to build it yourself.\n\nOnce you've added a provider as a dependency, it can be registered with OpenFeature like this:\n\n```swift\nawait OpenFeatureAPI.shared.setProviderAndWait(provider: MyProvider())\n```\n\n\u003e Asynchronous API that doesn't wait is also available\n\n### Targeting\n\nSometimes, the value of a flag must consider some dynamic criteria about the application or user, such as the user's location, IP, email address, or the server's location.\nIn OpenFeature, we refer to this as [targeting](https://openfeature.dev/specification/glossary#targeting).\nIf the flag management system you're using supports targeting, you can provide the input data using the [evaluation context](https://openfeature.dev/docs/reference/concepts/evaluation-context).\n\n```swift\n// Configure your evaluation context and pass it to OpenFeatureAPI\nlet ctx = MutableContext(\n    targetingKey: userId,\n    structure: MutableStructure(attributes: [\"product\": Value.string(productId)]))\nOpenFeatureAPI.shared.setEvaluationContext(evaluationContext: ctx)\n```\n\n### Hooks\n\n[Hooks](https://openfeature.dev/docs/reference/concepts/hooks) allow for custom logic to be added at well-defined points of the flag evaluation life-cycle.\nLook [here](https://openfeature.dev/ecosystem/?instant_search%5BrefinementList%5D%5Btype%5D%5B0%5D=Hook\u0026instant_search%5BrefinementList%5D%5Btechnology%5D%5B0%5D=Swift) for a complete list of available hooks.\nIf the hook you're looking for hasn't been created yet, see the [develop a hook](#develop-a-hook) section to learn how to build it yourself.\n\nOnce you've added a hook as a dependency, it can be registered at the global, client, or flag invocation level.\n\n```swift\n// add a hook globally, to run on all evaluations\nOpenFeatureAPI.shared.addHooks(hooks: ExampleHook())\n\n// add a hook on this client, to run on all evaluations made by this client\nval client = OpenFeatureAPI.shared.getClient()\nclient.addHooks(ExampleHook())\n\n// add a hook for this evaluation only\n_ = client.getValue(\n    key: \"key\",\n    defaultValue: false,\n    options: FlagEvaluationOptions(hooks: [ExampleHook()]))\n```\n### Tracking\n\nTracking is not yet available in the iOS SDK.\n\n### Logging\n\nLogging customization is not yet available in the iOS SDK.\n\n### Named clients\n\nSupport for named clients is not yet available in the iOS SDK.\n\n### Eventing\n\nEvents allow you to react to state changes in the provider or underlying flag management system, such as flag definition changes, provider readiness, or error conditions.\nInitialization events (`PROVIDER_READY` on success, `PROVIDER_ERROR` on failure) are dispatched for every provider.\nSome providers support additional events, such as `PROVIDER_CONFIGURATION_CHANGED`.\n\nPlease refer to the documentation of the provider you're using to see what events are supported.\n\n```swift\nlet cancellable = OpenFeatureAPI.shared.observe().sink { event in\n    switch event {\n    case ProviderEvent.ready:\n        // ...\n    default:\n        // ...\n    }\n}\n```\n\n### Shutdown\n\nA shutdown function is not yet available in the iOS SDK.\n\n## Extending\n\n### Develop a provider\n\nTo develop a provider, you need to create a new project and include the OpenFeature SDK as a dependency.\nYou’ll then need to write the provider by implementing the `FeatureProvider` interface exported by the OpenFeature SDK.\n\n```swift\nimport OpenFeature\n\nfinal class CustomProvider: FeatureProvider {\n    var hooks: [any Hook] = []\n    var metadata: ProviderMetadata = CustomMetadata()\n\n    func initialize(initialContext: EvaluationContext?) async {\n        // add context-aware provider initialisation\n    }\n\n    func onContextSet(oldContext: EvaluationContext?, newContext: EvaluationContext) async {\n        // add necessary changes on context change\n    }\n\n    func getBooleanEvaluation(\n        key: String,\n        defaultValue: Bool,\n        context: EvaluationContext?\n    ) throws -\u003e ProviderEvaluation\u003cBool\u003e {\n        // resolve a boolean flag value\n    }\n\n    ...\n}\n\n```\n\u003e Built a new provider? [Let us know](https://github.com/open-feature/openfeature.dev/issues/new?assignees=\u0026labels=provider\u0026projects=\u0026template=document-provider.yaml\u0026title=%5BProvider%5D%3A+) so we can add it to the docs!\n\n### Develop a hook\n\nTo develop a hook, you need to create a new project and include the OpenFeature SDK as a dependency.\nImplement your own hook by conforming to the `Hook interface`.\nTo satisfy the interface, all methods (`Before`/`After`/`Finally`/`Error`) need to be defined.\n\n```swift\nclass BooleanHook: Hook {\n    typealias HookValue = Bool\n\n    func before\u003cHookValue\u003e(ctx: HookContext\u003cHookValue\u003e, hints: [String: Any]) {\n        // do something\n    }\n\n    func after\u003cHookValue\u003e(ctx: HookContext\u003cHookValue\u003e, details: FlagEvaluationDetails\u003cHookValue\u003e, hints: [String: Any]) {\n        // do something\n    }\n\n    func error\u003cHookValue\u003e(ctx: HookContext\u003cHookValue\u003e, error: Error, hints: [String: Any]) {\n        // do something\n    }\n\n    func finally\u003cHookValue\u003e(ctx: HookContext\u003cHookValue\u003e, hints: [String: Any]) {\n        // do something\n    }\n}\n```\n\n\u003e Built a new hook? [Let us know](https://github.com/open-feature/openfeature.dev/issues/new?assignees=\u0026labels=hook\u0026projects=\u0026template=document-hook.yaml\u0026title=%5BHook%5D%3A+) so we can add it to the docs!\n\n\u003c!-- x-hide-in-docs-start --\u003e\n## ⭐️ Support the project\n\n- Give this repo a ⭐️!\n- Follow us on social media:\n  - Twitter: [@openfeature](https://twitter.com/openfeature)\n  - LinkedIn: [OpenFeature](https://www.linkedin.com/company/openfeature/)\n- Join us on [Slack](https://cloud-native.slack.com/archives/C0344AANLA1)\n- For more, check out our [community page](https://openfeature.dev/community/)\n\n## 🤝 Contributing\n\nInterested in contributing? Great, we'd love your help! To get started, take a look at the [CONTRIBUTING](CONTRIBUTING.md) guide.\n\n### Thanks to everyone who has already contributed\n\n\u003ca href=\"https://github.com/open-feature/swift-sdk/graphs/contributors\"\u003e\n  \u003cimg src=\"https://contrib.rocks/image?repo=open-feature/swift-sdk\" alt=\"Pictures of the folks who have contributed to the project\" /\u003e\n\u003c/a\u003e\n\nMade with [contrib.rocks](https://contrib.rocks).\n\u003c!-- x-hide-in-docs-end --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-feature%2Fswift-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopen-feature%2Fswift-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-feature%2Fswift-sdk/lists"}