Skip to content

Commit 151ac0e

Browse files
committed
refactor: rename and update readme
1 parent f19bad5 commit 151ac0e

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

README.md

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111

1212
`FSContactStore` is a Swift package that provides a convenient and easy-to-use interface for interacting with Apple's `Contacts` framework on iOS and macOS.
1313

14-
## Features:
14+
## Features
1515

1616
* Simplified authorization handling for requesting access to contacts.
1717
* Flexible fetching options for retrieving contacts with filtering, sorting, and specifying properties to retrieve.
1818
* Support for unified contacts, which combine information from multiple sources.
1919
* Shared instance for quick access to common functionalities.
2020
* Customizable save requests to allow tailoring logic for adding, updating, and deleting contacts.
2121

22-
## Installation:
22+
## Installation
2323

2424
Add the package to your Package.swift file:
2525

@@ -35,7 +35,7 @@ Import the package in your Swift files:
3535
import ContactStore
3636
```
3737

38-
## Usage:
38+
## Usage
3939

4040
1. Import the library:
4141

@@ -120,7 +120,7 @@ try store.delete(contact)
120120

121121
By default, `ContactStore` uses a standard `CNSaveRequest` instance.
122122
You can modify the static closure `ContactStore.makeCNSaveRequest` to inject custom logic or provide different request implementations.
123-
**Important:** To modify the ContactStore.makeCNSaveRequest closure, you must use the use(_:) method.
123+
**Important:** To modify the `ContactStore.makeCNSaveRequest` closure, you must use the `use(_:)` method.
124124

125125
```swift
126126
ContactStore.use { request in
@@ -133,7 +133,33 @@ ContactStore.use { request in
133133
This code updates the `ContactStore.makeCNSaveRequest` closure to accept a `CNSaveRequest` instance as an argument,
134134
make any necessary changes to it, and then return the updated request.
135135

136-
## Contributions:
136+
7. Customizing Authorization Status (Optional):
137+
138+
By default, `ContactStore` uses the actual authorization status from the system's `CNContactStore`.
139+
However, you can override this behavior with a custom closure to inject specific authorization statuses for testing or other purposes.
140+
141+
Here's how to customize the authorization status:
142+
143+
**Use the `use(_:)` method:**
144+
145+
- Call the `use(_:)` method on `ContactStore` to provide a custom closure for creating `CNAuthorizationStatus` instances.
146+
- The closure accepts no arguments and returns a `CNAuthorizationStatus` value.
147+
148+
**Implement the closure logic:**
149+
150+
- Within the closure, specify the desired authorization status to be returned.
151+
You can return a fixed value or implement more complex logic based on your needs.
152+
153+
```swift
154+
ContactStore.use {
155+
return .denied // Simulate denied authorization status
156+
}
157+
158+
let currentStatus = ContactStore.authorizationStatus()
159+
// currentStatus will now be .denied
160+
```
161+
162+
## Contributions
137163

138164
We welcome contributions to this project! Please feel free to open issues or pull requests to help improve the package.
139165

Sources/ContactStore/ContactStore.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public final class ContactStore: ContactStoreProtocol {
3737
CNSaveRequest()
3838
}
3939

40-
/// A closure for creating `CNAuthorizationStatus` instances, allowing for custom implementations.
41-
private static var makeAuthorizationStatus: () -> CNAuthorizationStatus = {
40+
/// A closure for creating `CNAuthorizationStatus` instances, allowing set needed status.
41+
private static var makeCNAuthorizationStatus: () -> CNAuthorizationStatus = {
4242
CNContactStore.authorizationStatus(for: .contacts)
4343
}
4444

@@ -55,7 +55,7 @@ public final class ContactStore: ContactStoreProtocol {
5555
///
5656
/// - Returns: The current authorization status (e.g., .authorized, .denied).
5757
public func authorizationStatus() -> CNAuthorizationStatus {
58-
let status = Self.makeAuthorizationStatus
58+
let status = Self.makeCNAuthorizationStatus
5959
return status()
6060
}
6161

@@ -202,6 +202,6 @@ public final class ContactStore: ContactStoreProtocol {
202202
///
203203
/// - Parameter make: The closure that creates a `CNAuthorizationStatus` instance.
204204
func use(_ make: @escaping () -> CNAuthorizationStatus) {
205-
Self.makeAuthorizationStatus = make
205+
Self.makeCNAuthorizationStatus = make
206206
}
207207
}

0 commit comments

Comments
 (0)