问题描述
在SwiftUI
应用中,我面临着新的挑战,希望有人能给我一些提示或指导。到目前为止,我所看到的在应用程序各部分之间进行通信的机制似乎不太适合。但这可能是由于我在SwiftUI
方面的经验仍然有限。
首先是相关代码:
class SceneDelegate {
... lot of code irrelevant to the question ...
func scene(_ scene: UIScene,continue userActivity: NSUserActivity) {
... useful things happening for the app ...
// Now the view should change ... by some mechanism.
// This is the point of the question.
}
}
和:
struct ContentView: View {
... lot of code irrelevant to the question ...
var body: some View {
vstack {
... code to draw the view ...
}
... more code to draw the view ...
}
}
第二,我的问题是:在 scene(:continue?
我想到了一些想法,以便在 scene(:continue )函数中执行可能会影响视图绘制的事情。
不幸的是,当尝试实现时,我意识到绘制视图的代码是在 scene(:continue 函数之前执行的。因此,我需要其他机制(通知之类的,绑定之类的? )重新绘制视图。
是否有好的做法或标准方法?
解决方法
在这种情况下使用[
{
"id": 4379711799354,"variant_id": 31291380727866,"title": "*NEW* Kayslin Sneaker in Blush","quantity": 1,"sku": "79000212","variant_title": "3Y","vendor": "TESTVENDOR","fulfillment_service": "manual","product_id": 4371426607162,"requires_shipping": true,"taxable": true,"gift_card": false,"name": "*NEW* Kayslin Sneaker in Blush - 3Y","variant_inventory_management": "shopify","properties": [
{
"name": "Item Ships Separately","value": "✓"
}
],"product_exists": true,"fulfillable_quantity": 0,"grams": 490,"price": "68.00","total_discount": "0.00","fulfillment_status": "fulfilled","pre_tax_price": "68.00","price_set": {
"shop_money": {
"amount": "68.00","currency_code": "USD"
},"presentment_money": {
"amount": "68.00","currency_code": "USD"
}
},"pre_tax_price_set": {
"shop_money": {
"amount": "68.00","total_discount_set": {
"shop_money": {
"amount": "0.00","presentment_money": {
"amount": "0.00","discount_allocations": [],"admin_graphql_api_id": "gid:\/\/shopify\/LineItem\/4379711799354","tax_lines": [
{
"title": "CT STATE TAX","price": "0.00","rate": 0.0,"price_set": {
"shop_money": {
"amount": "0.00","currency_code": "USD"
},"presentment_money": {
"amount": "0.00","currency_code": "USD"
}
}
}
],"origin_location": {
"id": 624876322874,"country_code": "US","province_code": "TX","name": "Joyfolie","address1": "1809 W Frankford Rd #160 ","address2": "","city": "Carrollton","zip": "75007"
}
},{
"id": 4379711832122,"variant_id": 31031946838074,"title": "*NEW* Mama Bird Necklace Set in Gold","sku": "83000109","variant_title": "","product_id": 4320751878202,"name": "*NEW* Mama Bird Necklace Set in Gold","properties": [],"grams": 113,"price": "29.50","pre_tax_price": "29.50","price_set": {
"shop_money": {
"amount": "29.50","presentment_money": {
"amount": "29.50","pre_tax_price_set": {
"shop_money": {
"amount": "29.50","admin_graphql_api_id": "gid:\/\/shopify\/LineItem\/4379711832122","presentment_money": {
"amount":
是合适的
EnvironmentObject