Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaisukeNagata/c6af55ae7896e8198492b0c0d9168396 to your computer and use it in GitHub Desktop.
Save DaisukeNagata/c6af55ae7896e8198492b0c0d9168396 to your computer and use it in GitHub Desktop.
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

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"
}

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