【发布时间】:2020-03-12 08:32:26
【问题描述】:
我有文本字段,我需要使用静态函数更改文本字段中的文本。
import SwiftUI
struct MainScreen: View
{
@State static var mytext = "TEXT"
var body: some View
{
Text(MainScreen.mytext)
}
public static func showtext(newtext: String)
{
MainScreen.mytext = newtext
}
}
我该怎么做?或者如果我要使用@State var mytext = "TEXT",我怎样才能在静态函数中获取 MainScreen.self?
P.S.:对不起我的英语)))
【问题讨论】:
-
您希望通过将@State 变量设为静态来实现什么目的?