මේ කෝඩ් එක වැඩ කරන්නෙ නැත්තෙ මොකෝ කියල වැඩ්ඩෙක් කියපන්කො. extension එක ඇතුලෙ තියෙන ෆන්ශන් එකෙන් stateObject එකට අන්ක "8" සෙට් කරනව, ඊට පස්සෙ රිසල්ට් එක environmentObject එකක් හරහා අනිත් වීව්ස් වලට ගන්නයි ඕනෙ, ටෙක්ස්ට්බොක්ස් එකේ "8" ගන්න විදිහ. උබලට මේ ස්විෆ්ට්යූඅයි එක සෙට් ද බන්?
අනිත් අයත් ප්රශ්න තියෙනවනම් දාන්න දන්න දේවල් වලින් හෙල්ප් කරන්නම්
Swift:
import SwiftUI
@main
struct temp3App: App {
@StateObject var thisClassLocal = ThisClass(thisIn: 7)
var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(ThisClass(thisIn: 7))
}
}
}
struct ContentView: View {
var body: some View {
@StateObject var thisClassLocal = ThisClass(thisIn: 7)
VStack {
Text(temp3App().thisClassLocal.thisVariableOut.description)
}
.padding()
}
}
extension temp3App {
func ThisFunction() {
@StateObject var thisClassLocal2 = ThisClass(thisIn: 7)
thisClassLocal2.thisVariableOut = 8
}
}
class ThisClass: ObservableObject {
@Published var thisVariableOut: Int
init(thisIn: Int) {
self.thisVariableOut = thisIn
}
}
අනිත් අයත් ප්රශ්න තියෙනවනම් දාන්න දන්න දේවල් වලින් හෙල්ප් කරන්නම්