Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update API descriptions
  • Loading branch information
ra1028 committed Oct 3, 2025
commit 94f1a6703eed671378f0916d7d52d60ab681b7cc
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,47 @@ struct CounterView: View {

</details>

#### [latest(_:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atom/latest(_:))

| |Description|
|:--------------|:----------|
|Summary |Provides the latest value that matches the specified condition instead of the current value.|
|Output |`T?`|
|Compatible |All atom types.|
|Use Case |Keep last valid value, Retain matching state|

<details><summary><code>📖 Example</code></summary>

```swift
struct Item {
let id: Int
let isValid: Bool
}

struct ItemAtom: StateAtom, Hashable {
func defaultValue(context: Context) -> Item {
Item(id: 0, isValid: false)
}
}

struct ExampleView: View {
@Watch(ItemAtom())
var currentItem

@Watch(ItemAtom().latest(\.isValid))
var latestValidItem

var body: some View {
VStack {
Text("Current ID: \(currentItem.id)")
Text("Latest Valid ID: \(latestValidItem?.id ?? 0)")
}
}
}
```

</details>

#### [changes(of:)](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/atom/changes(of:))

| |Description|
Expand Down
4 changes: 2 additions & 2 deletions Sources/Atoms/Modifier/LatestModifier.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
public extension Atom {
/// Provides the latest value where the specified key path returns `true` instead of the current value.
/// Provides the latest value that matches the specified condition instead of the current value.
///
/// ```swift
/// struct Item {
Expand Down Expand Up @@ -40,7 +40,7 @@ public extension Atom {
#endif
}

/// A modifier that provides the latest value where the specified key path returns `true` instead of the current value.
/// A modifier that provides the latest value that matches the specified condition instead of the current value.
///
/// Use ``Atom/latest(_:)`` instead of using this modifier directly.
public struct LatestModifier<Base>: AtomModifier {
Expand Down