Skip to content

Commit dbdd502

Browse files
docs: Update README to latest template (#28)
Signed-off-by: Fabrizio Demaria <[email protected]>
1 parent 5ddf45d commit dbdd502

File tree

1 file changed

+142
-66
lines changed

1 file changed

+142
-66
lines changed

README.md

+142-66
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,48 @@
11
<!-- markdownlint-disable MD033 -->
2+
<!-- x-hide-in-docs-start -->
23
<p align="center">
34
<picture>
4-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/open-feature/community/0e23508c163a6a1ac8c0ced3e4bd78faafe627c7/assets/logo/horizontal/white/openfeature-horizontal-white.svg">
5-
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/open-feature/community/0e23508c163a6a1ac8c0ced3e4bd78faafe627c7/assets/logo/horizontal/black/openfeature-horizontal-black.svg">
6-
<img align="center" alt="OpenFeature Logo">
5+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/open-feature/community/0e23508c163a6a1ac8c0ced3e4bd78faafe627c7/assets/logo/horizontal/white/openfeature-horizontal-white.svg" />
6+
<img align="center" alt="OpenFeature Logo" src="https://raw.githubusercontent.com/open-feature/community/0e23508c163a6a1ac8c0ced3e4bd78faafe627c7/assets/logo/horizontal/black/openfeature-horizontal-black.svg" />
77
</picture>
88
</p>
99

10-
<h2 align="center">OpenFeature Swift SDK</h2>
10+
<h2 align="center">OpenFeature iOS SDK</h2>
1111

12-
![Status](https://img.shields.io/badge/lifecycle-alpha-a0c3d2.svg)
12+
<!-- x-hide-in-docs-end -->
13+
<!-- The 'github-badges' class is used in the docs -->
14+
<p align="center" class="github-badges">
15+
<!-- TODO: update this with the version of the SDK your implementation supports -->
1316

14-
## 👋 Hey there! Thanks for checking out the OpenFeature Swift SDK
17+
<a href="https://github.com/open-feature/spec/releases/tag/v0.7.0">
18+
<img alt="Specification" src="https://img.shields.io/static/v1?label=specification&message=v0.7.0&color=yellow&style=for-the-badge" />
19+
</a>
20+
<!-- x-release-please-start-version -->
1521

16-
### What is OpenFeature?
22+
<a href="https://github.com/open-feature/swift-sdk/releases/tag/0.0.2">
23+
<img alt="Release" src="https://img.shields.io/static/v1?label=release&message=v0.0.2&color=blue&style=for-the-badge" />
24+
</a>
1725

18-
[OpenFeature][openfeature-website] is an open specification that provides a vendor-agnostic, community-driven API for feature flagging that works with your favorite feature flag management tool.
26+
<!-- x-release-please-end -->
27+
<br/>
28+
<img alt="Status" src="https://img.shields.io/badge/lifecycle-alpha-a0c3d2.svg" />
29+
</p>
30+
<!-- x-hide-in-docs-start -->
1931

20-
### Why standardize feature flags?
32+
[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.
2133

22-
Standardizing feature flags unifies tools and vendors behind a common interface which avoids vendor lock-in at the code level. Additionally, it offers a framework for building extensions and integrations and allows providers to focus on their unique value proposition.
34+
<!-- x-hide-in-docs-end -->
35+
## 🚀 Quick start
2336

24-
## 🔍 Requirements
37+
### Requirements
2538

2639
- The minimum iOS version supported is: `iOS 14`.
2740

2841
Note 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.).
2942

30-
## 📦 Installation
43+
### Install
3144

32-
### Xcode Dependencies
45+
#### Xcode Dependencies
3346

3447
You have two options, both start from File > Add Packages... in the code menu.
3548

@@ -43,7 +56,7 @@ First, ensure you have your GitHub account added as an option (+ > Add Source Co
4356

4457
**Note:** Option 2 is only recommended if you are making changes to the client SDK.
4558

46-
### Swift Package Manager
59+
#### Swift Package Manager
4760

4861
If you manage dependencies through SPM, in the dependencies section of Package.swift add:
4962

@@ -58,14 +71,7 @@ and in the target dependencies section add:
5871
.product(name: "OpenFeature", package: "swift-sdk"),
5972
```
6073

61-
## 🌟 Features
62-
63-
- Support for various backend [providers](https://openfeature.dev/docs/reference/concepts/provider)
64-
- Easy integration and extension via [hooks](https://openfeature.dev/docs/reference/concepts/hooks)
65-
- Bool, string, numeric, and object flag types
66-
- [Context-aware](https://openfeature.dev/docs/reference/concepts/evaluation-context) evaluation
67-
68-
## 🚀 Usage
74+
### Usage
6975

7076
```swift
7177
import OpenFeature
@@ -85,24 +91,97 @@ let client = OpenFeatureAPI.shared.getClient()
8591
let flagValue = client.getBooleanValue(key: "boolFlag", defaultValue: false)
8692
```
8793

88-
Setting a new provider or setting a new evaluation context are synchronous operations. The provider might execute I/O operations as part of these method calls (e.g. fetching flag evaluations from the backend and store them in a local cache). It's advised to not interact with the OpenFeature client until the relevant event has been emitted (see events below).
94+
Setting a new provider or setting a new evaluation context might trigger asynchronous operations (e.g. fetching flag evaluations from the backend and store them in a local cache). It's advised to not interact with the OpenFeature client until the `ProviderReady` event has been emitted (see [Eventing](#eventing) below).
95+
96+
## 🌟 Features
97+
98+
99+
| Status | Features | Description |
100+
| ------ | ------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
101+
|| [Providers](#providers) | Integrate with a commercial, open source, or in-house feature management tool. |
102+
|| [Targeting](#targeting) | Contextually-aware flag evaluation using [evaluation context](https://openfeature.dev/docs/reference/concepts/evaluation-context). |
103+
|| [Hooks](#hooks) | Add functionality to various stages of the flag evaluation life-cycle. |
104+
|| [Logging](#logging) | Integrate with popular logging packages. |
105+
|| [Named clients](#named-clients) | Utilize multiple providers in a single application. |
106+
|| [Eventing](#eventing) | React to state changes in the provider or flag management system. |
107+
|| [Shutdown](#shutdown) | Gracefully clean up a provider during application shutdown. |
108+
|| [Extending](#extending) | Extend OpenFeature with custom providers and hooks. |
109+
110+
<sub>Implemented: ✅ | In-progress: ⚠️ | Not implemented yet: ❌</sub>
111+
112+
### Providers
113+
114+
[Providers](https://openfeature.dev/docs/reference/concepts/provider) are an abstraction between a flag management system and the OpenFeature SDK.
115+
Look [here](https://openfeature.dev/ecosystem?instant_search%5BrefinementList%5D%5Btype%5D%5B0%5D=Provider&instant_search%5BrefinementList%5D%5Btechnology%5D%5B0%5D=Swift) for a complete list of available providers.
116+
If 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.
117+
118+
Once you've added a provider as a dependency, it can be registered with OpenFeature like this:
119+
120+
```swift
121+
OpenFeatureAPI.shared.setEvaluationContext(evaluationContext: ctx)
122+
```
123+
124+
### Targeting
89125

90-
Please refer to our [documentation on static-context APIs](https://github.com/open-feature/spec/pull/171) for further information on how these APIs are structured for the use-case of mobile clients.
126+
Sometimes, 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.
127+
In OpenFeature, we refer to this as [targeting](https://openfeature.dev/specification/glossary#targeting).
128+
If 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).
91129

92-
### Events
130+
```swift
131+
// Configure your evaluation context and pass it to OpenFeatureAPI
132+
let ctx = MutableContext(
133+
targetingKey: userId,
134+
structure: MutableStructure(attributes: ["product": Value.string(productId)]))
135+
OpenFeatureAPI.shared.setEvaluationContext(evaluationContext: ctx)
136+
```
137+
138+
### Hooks
139+
140+
[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.
141+
Look [here](https://openfeature.dev/ecosystem/?instant_search%5BrefinementList%5D%5Btype%5D%5B0%5D=Hook&instant_search%5BrefinementList%5D%5Btechnology%5D%5B0%5D=Swift) for a complete list of available hooks.
142+
If 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.
143+
144+
Once you've added a hook as a dependency, it can be registered at the global, client, or flag invocation level.
145+
146+
```swift
147+
// add a hook globally, to run on all evaluations
148+
OpenFeatureAPI.shared.addHooks(hooks: ExampleHook())
149+
150+
// add a hook on this client, to run on all evaluations made by this client
151+
val client = OpenFeatureAPI.shared.getClient()
152+
client.addHooks(ExampleHook())
153+
154+
// add a hook for this evaluation only
155+
_ = client.getValue(
156+
key: "key",
157+
defaultValue: false,
158+
options: FlagEvaluationOptions(hooks: [ExampleHook()]))
159+
```
160+
161+
### Eventing
93162

94163
Events 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.
95-
Initialization events (`PROVIDER_READY` on success, `PROVIDER_ERROR` on failure) are emitted for every provider.
164+
Initialization events (`PROVIDER_READY` on success, `PROVIDER_ERROR` on failure) are dispatched for every provider.
96165
Some providers support additional events, such as `PROVIDER_CONFIGURATION_CHANGED`.
97-
Please refer to the documentation of the provider you're using to see what events are supported and when they are emitted.
98166

99-
To register a handler for API level provider events, use the `OpenFeatureAPI` `addHandler(observer:selector:event:)` function. Event handlers can also be removed using the equivalent `removeHandler` function. `Client`s also provide add and remove functions for listening to that specific client. A `ProviderEvent` enum is defined to ease subscription.
167+
Please refer to the documentation of the provider you're using to see what events are supported.
100168

101-
Events can contain extra information in the `userInfo` dictionary of the notification. All events will contain a reference to the provider that emitted the event (under the `providerEventDetailsKeyProvider` key). Error events will also provide a reference to the underlying error (under the `providerEventDetailsKeyError` key). Finally, client specific events will contain a reference to the client (under the `providerEventDetailsKeyClient` key)
169+
```swift
170+
OpenFeatureAPI.shared.addHandler(
171+
observer: self, selector: #selector(readyEventEmitted(notification:)), event: .ready
172+
)
102173

103-
### Providers
174+
func readyEventEmitted(notification: NSNotification) {
175+
// to something now that the provider is ready
176+
}
177+
```
178+
179+
## Extending
180+
181+
### Develop a provider
104182

105-
To develop a provider, you need to create a new project and include the OpenFeature SDK as a dependency. This can be a new repository or included in the existing contrib repository available under the OpenFeature organization. Finally, you’ll then need to write the provider itself. This can be accomplished by implementing the `FeatureProvider` protocol exported by the OpenFeature SDK.
183+
To develop a provider, you need to create a new project and include the OpenFeature SDK as a dependency.
184+
You’ll then need to write the provider by implementing the `FeatureProvider` interface exported by the OpenFeature SDK.
106185

107186
```swift
108187
import OpenFeature
@@ -127,64 +206,61 @@ final class CustomProvider: FeatureProvider {
127206
// resolve a boolean flag value
128207
}
129208

130-
func getStringEvaluation(
131-
key: String,
132-
defaultValue: String,
133-
context: EvaluationContext?
134-
) throws -> ProviderEvaluation<String> {
135-
// resolve a string flag value
209+
...
210+
}
211+
212+
```
213+
> Built a new provider? [Let us know](https://github.com/open-feature/openfeature.dev/issues/new?assignees=&labels=provider&projects=&template=document-provider.yaml&title=%5BProvider%5D%3A+) so we can add it to the docs!
214+
215+
### Develop a hook
216+
217+
To develop a hook, you need to create a new project and include the OpenFeature SDK as a dependency.
218+
Implement your own hook by conforming to the `Hook interface`.
219+
To satisfy the interface, all methods (`Before`/`After`/`Finally`/`Error`) need to be defined.
220+
221+
```swift
222+
class BooleanHook: Hook {
223+
typealias HookValue = Bool
224+
225+
func before<HookValue>(ctx: HookContext<HookValue>, hints: [String: Any]) {
226+
// do something
136227
}
137228

138-
func getIntegerEvaluation(
139-
key: String,
140-
defaultValue: Int64,
141-
context: EvaluationContext?
142-
) throws -> ProviderEvaluation<Int64> {
143-
// resolve an integer flag value
229+
func after<HookValue>(ctx: HookContext<HookValue>, details: FlagEvaluationDetails<HookValue>, hints: [String: Any]) {
230+
// do something
144231
}
145232

146-
func getDoubleEvaluation(
147-
key: String,
148-
defaultValue: Double,
149-
context: EvaluationContext?
150-
) throws -> ProviderEvaluation<Double> {
151-
// resolve a double flag value
233+
func error<HookValue>(ctx: HookContext<HookValue>, error: Error, hints: [String: Any]) {
234+
// do something
152235
}
153236

154-
func getObjectEvaluation(
155-
key: String,
156-
defaultValue: Value,
157-
context: EvaluationContext?
158-
) throws -> ProviderEvaluation<Value> {
159-
// resolve an object flag value
237+
func finallyAfter<HookValue>(ctx: HookContext<HookValue>, hints: [String: Any]) {
238+
// do something
160239
}
161240
}
162-
163241
```
164242

243+
> Built a new hook? [Let us know](https://github.com/open-feature/openfeature.dev/issues/new?assignees=&labels=hook&projects=&template=document-hook.yaml&title=%5BHook%5D%3A+) so we can add it to the docs!
244+
245+
<!-- x-hide-in-docs-start -->
165246
## ⭐️ Support the project
166247

167248
- Give this repo a ⭐️!
168249
- Follow us on social media:
169-
- Twitter: [@openfeature](https://twitter.com/openfeature)
170-
- LinkedIn: [OpenFeature](https://www.linkedin.com/company/openfeature/)
250+
- Twitter: [@openfeature](https://twitter.com/openfeature)
251+
- LinkedIn: [OpenFeature](https://www.linkedin.com/company/openfeature/)
171252
- Join us on [Slack](https://cloud-native.slack.com/archives/C0344AANLA1)
172-
- For more check out our [community page](https://openfeature.dev/community/)
253+
- For more, check out our [community page](https://openfeature.dev/community/)
173254

174255
## 🤝 Contributing
175256

176257
Interested in contributing? Great, we'd love your help! To get started, take a look at the [CONTRIBUTING](CONTRIBUTING.md) guide.
177258

178-
### Thanks to everyone that has already contributed
259+
### Thanks to everyone who has already contributed
179260

180261
<a href="https://github.com/open-feature/swift-sdk/graphs/contributors">
181262
<img src="https://contrib.rocks/image?repo=open-feature/swift-sdk" alt="Pictures of the folks who have contributed to the project" />
182263
</a>
183264

184265
Made with [contrib.rocks](https://contrib.rocks).
185-
186-
## 📜 License
187-
188-
[Apache License 2.0](LICENSE)
189-
190-
[openfeature-website]: https://openfeature.dev
266+
<!-- x-hide-in-docs-end -->

0 commit comments

Comments
 (0)