Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SwiftUI_Method_BInd
import SwiftUI
struct ContentView: View {
@ObservedObject var bind = STBind()
init() {
bind.st = "111"
}
var body: some View {
VStack {
Text(self.a(st: bind))
.onTapGesture {
if self.bind.st == "111" {
self.bind.st = "222"
} else {
self.bind.st = "111"
}
}
}
}
func a(st: STBind) -> String {
return st.st
}
}
class STBind: ObservableObject {
@Published var st = String()
}
@daisukenagata
Copy link
Author

daisukenagata commented Jul 19, 2020

import SwiftUI

struct ContentView: View {
    
    @ObservedObject var bind = STBind()

    var body: some View {
        VStack {
            Text(self.a())
                .onTapGesture {
                    if self.bind.st == "111" {
                        self.bind.st = "222"
                    } else {
                        self.bind.st = "111"
                    }
                    _ = self.a()
            }
        }
    }
    
    func a() -> String {
        return self.bind.st
    }
}

class STBind: ObservableObject {
    @Published var st = "111"
}

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment