从 ObservableObject 类内部的视图传递变量?
我得到了这个结构的
struct Calendar: View {
@State private var selectDate = Date()
var body: some View {
// my code
}
Class fetchmydate: ObservableObject {
func fetchmydata (){
// i want to pass selectDate to here in "dd-mm-yyyy" format as string
}
}
}
想法,我想将 selectdate 从视图传递到 ObservedObject 类,而不是反之亦然,但采用这种格式“dd-mm-yyyy”并作为字符串。如果我没有通过这个选定的日期,它会说它无法读取函数内的选定日期。
我知道这是一个奇怪的问题,但如果它不能在逻辑中完成(通过),那么你建议如何传递日期数据,非常感谢我的朋友们。
i got this struct
struct Calendar: View {
@State private var selectDate = Date()
var body: some View {
// my code
}
Class fetchmydate: ObservableObject {
func fetchmydata (){
// i want to pass selectDate to here in "dd-mm-yyyy" format as string
}
}
}
the idea i want to pass the selectdate from the view into observedobject class and not vice versa, but in this format "dd-mm-yyyy" and as a string. and if i don't pass this selected date it says it can't read the selected date inside the function.
i know it is somehow weird question but if it can't be done in logic (passing) then what do you suggest to pass the date data and thank you alot my friends.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你想要实现的目标并不是闻所未闻的,只是更容易将整个逻辑传递给 viewModel,我相信你正在寻找这个:
视图:
“视图模型”
What are you trying to achieve is not something unheard of, is just easier to pass the entire logic to the viewModel, I believe you are looking for this:
The view:
The "View Model"