> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/ios/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/ios/swiftui/data-flow/preferences/preferencekey/maxvalue-less-than-t-greater-than.md).

# MaxValue\<T>

{% tabs %}
{% tab title="📦  MaxValue" %}

```swift
// 2020.10.15：

import SwiftUI

// 📦 MaxValue<T: FloatingPoint>
public struct MaxValue<T: FloatingPoint>: PreferenceKey {
    // value type
    public typealias Value = T?
    // default value (nil == not set) 
    public static var defaultValue: Value { nil }
    // ⭐️ choose max value
    public static func reduce(value: inout Value, nextValue: () -> Value) {
        // ⭐️ [T?] --(compactMap)--> [T] --(max)--> T?
        value = [value, nextValue()].compactMap{ $0 }.max()
    }
}
```

{% endtab %}

{% tab title="👥  相關 " %}

* [🅿️ PreferenceKey](/ios/swiftui/data-flow/preferences/preferencekey.md)
  {% endtab %}
  {% endtabs %}
