---
title: "Discussion on \"Swift的Binding小纸条\" | Hashnode"
description: "Discussion on \"Swift的Binding小纸条\". 我们经常会使用Binding来把一个打通两个View。最常见的一个例子就是Picker:\n\n自定义Binding\n使用Binding实例\n如果我们在Picker选择发生变化时想做一些操作，就会发现问题了，因为Picker里不好写.onTapGesture。这时就需要使用自定义Binding变量了。最简单的方法，就是在selection参数处直接定义一个Binding，就像这段代码，一个Binding的实例有了get和set两个匿名函数，你可以完成自己的自定义操作了（联动改变choosed的值）。..."
url: "https://hashnode.com/posts/swift-custom-binding/628102420094f2f13f516517"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Swift的Binding小纸条](https://blog.hdcola.org/swift-custom-binding?utm_source=hashnode&utm_medium=feed)

我们经常会使用Binding来把一个打通两个View。最常见的一个例子就是Picker: 自定义Binding 使用Binding实例 如果我们在Picker选择发生变化时想做一些操作，就会发现问题了，因为Picker里不好写.onTapGesture。这时就需要使用自定义Binding变量了。最简单的方法，就是在selection参数处直接定义一个Binding，就像这段代码，一个Binding的实例有了get和set两个匿名函数，你可以完成自己的自定义操作了（联动改变choosed的值）。...

May 15, 2022 · 1 min read · blog.hdcola.org  
Read the article

-   [#xcode](https://hashnode.com/tag/xcode)
-   [#swift](https://hashnode.com/tag/swift)
-   [#swiftui](https://hashnode.com/tag/swiftui)

## Written by

[老房东](https://hashnode.com/@hdcola)

@hdcola · Quebec CA

  
[View profile](https://hashnode.com/@hdcola)

Let's enjoy life

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
