Skip to content

Commit 0f8860f

Browse files
committed
Document observation protocols
1 parent 1c0e873 commit 0f8860f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Source/Shared/Storage/KeyObservationRegistry.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
import Foundation
22

3+
/// A protocol used for adding and removing key observations
34
public protocol KeyObservationRegistry {
45
associatedtype S: StorageAware
56

7+
/**
8+
Registers observation closure which will be removed automatically
9+
when the weekly captured observer has been deallocated.
10+
- Parameter observer: Any object that helps to determine if the observation is still valid
11+
- Parameter key: Unique key to identify the object in the cache
12+
- Parameter closure: Observation closure
13+
- Returns: Token used to cancel the observation and remove the observation closure
14+
*/
615
@discardableResult
716
func addObserver<O: AnyObject>(
817
_ observer: O,
918
forKey key: String,
1019
closure: @escaping (O, S, KeyChange<S.T>) -> Void
1120
) -> ObservationToken
1221

22+
/// Removes observer by the given key.
1323
func removeObserver(forKey key: String)
24+
25+
/// Removes all registered key observers
1426
func removeAllKeyObservers()
1527
}
1628

Source/Shared/Storage/StorageObservationRegistry.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
import Foundation
22

3+
/// A protocol used for adding and removing storage observations
34
public protocol StorageObservationRegistry {
45
associatedtype S: StorageAware
56

7+
/**
8+
Registers observation closure which will be removed automatically
9+
when the weekly captured observer has been deallocated.
10+
- Parameter observer: Any object that helps to determine if the observation is still valid
11+
- Parameter closure: Observation closure
12+
- Returns: Token used to cancel the observation and remove the observation closure
13+
*/
614
@discardableResult
715
func addStorageObserver<O: AnyObject>(
816
_ observer: O,
917
closure: @escaping (O, S, StorageChange) -> Void
1018
) -> ObservationToken
1119

20+
/// Removes all registered key observers
1221
func removeAllStorageObservers()
1322
}
1423

0 commit comments

Comments
 (0)