Introduction
Welcome to the documentation for the Prephirences framework. This documentation aims to provide detailed information about the features and usage of the Prephirences framework.
Getting Started
To start using Prephirences in your project, follow the steps below:
- Install Prephirences using Cocoapods or manually include the framework files in your project.
- Import the Prephirences module into your Swift file:
“`swift
import Prephirences
“`
Features
The Prephirences framework offers the following key features:
- 1. Preference Providers: Prephirences provides different types of preference providers, such as UserDefaults, Keychain, Plist, and more. These providers make it easy to manage preferences and settings within your app.
- 2. Composite Preference Provider: The CompositePreferenceProvider allows you to group multiple preference providers into a single provider, simplifying preference management across different sources.
- 3. Preference Storage: Prephirences offers a convenient way to store preferences and retrieve them later using the `Prephirences` class.
- 4. PreferenceMutator: With Prephirences, you can implement preference mutators to manipulate preference values before they are stored or retrieved.
Installation
You can install Prephirences in your project using either Cocoapods or manually including the framework files.
- CocoaPods: Add the following line to your Podfile and run `pod install`:
“`ruby
pod ‘Prephirences’
“`
- Manual: Download the Prephirences framework from the official GitHub repository and drag the Prephirences.xcodeproj file into your Xcode workspace.
- In your project’s target settings, under “General” tab, add Prephirences as a dependency.
Usage
Once you have integrated Prephirences into your project, you can start using its features.
1. Preference Providers:
Prephirences provides several preference providers out-of-the-box. To use a preference provider, you need to initialize an instance of it, specifying the appropriate identifier (e.g., for UserDefaults provider, use `.standard`). Here’s an example:
“`swift
let userDefaultsProvider = UserDefaultsPreferenceProvider.standard
“`
2. Composite Preference Provider:
The CompositePreferenceProvider allows you to group multiple preference providers into a single provider. To create a composite provider, pass an array of preference providers to its initializer. Here’s an example:
“`swift
let compositeProvider = CompositePreferenceProvider([userDefaultsProvider, keychainProvider, plistProvider])
“`
3. Preference Storage:
To store and retrieve preferences easily, you can use the `Prephirences` class. Before using it, make sure to set the preferred preference provider as shown in the example below:
“`swift
Prephirences.preference = userDefaultsProvider
“`
Then, you can store and retrieve preferences directly:
“`swift
Prephirences.set(“John Doe”, forKey: “userName”)
let userName = Prephirences.string(forKey: “userName”)
“`
4. PreferenceMutator:
You can implement your own PreferenceMutator to modify the preference values before they are stored or retrieved. Simply follow the steps below:
- Implement the `PreferenceMutator` protocol:
“`swift
class MyPrefMutator: PreferenceMutator {
func mutate
// Implement your preference mutation logic here
return value
}
}
“`
- Register your custom mutator:
“`swift
Prephirences.registerMutator(MyPrefMutator())
“`
Conclusion
This concludes the documentation for the Prephirences framework. You should now have a better understanding of its features and how to use them in your Swift projects. For more detailed information and example code, please refer to the official Prephirences documentation on GitHub.