Swift 如何设计watchOS 6独立应用程序的复杂性?

Swift 如何设计watchOS 6独立应用程序的复杂性?,swift,firebase,swiftui,watchos,apple-watch-complication,Swift,Firebase,Swiftui,Watchos,Apple Watch Complication,我在watchOS 6上有一个独立的应用程序,在我的应用程序中,我使用Firestore REST API使用URLSession向用户显示数据 由于CloudFireStoreRESTAPI返回JSON字符串,为了处理数据,我创建了嵌套结构。示例:要访问特定响应中的“title”,我执行以下操作:response.mapValue.fields.title.stringValue。 该应用目前运行良好。从长远来看,我计划创建URLSessions作为后台任务。现在,每次使用数据的列表视图上的.

我在watchOS 6上有一个独立的应用程序,在我的应用程序中,我使用Firestore REST API使用
URLSession
向用户显示数据

由于CloudFireStoreRESTAPI返回JSON字符串,为了处理数据,我创建了嵌套结构。示例:要访问特定响应中的“title”,我执行以下操作:
response.mapValue.fields.title.stringValue
。 该应用目前运行良好。从长远来看,我计划创建URLSessions作为后台任务。现在,每次使用数据的
列表
视图上的
.onAppear(functionToUserSession())
)呈现视图时,我都会调用
URLSession

现在我想实现的下一件事是这个特定应用程序的复杂性。 我刚接触Swift和SwiftUI,刚开始的时候感觉最困难。我在线学习的所有教程都使用
WKExtensionDelegate
来获取复杂度的数据模型。 但就我而言,我甚至没有数据模型!我只是让结构以嵌套方式调用其他结构,以便处理从API调用获得的JSON响应

非常感谢任何能让我理解这一点的帮助

下面是一些代码,可以更好地理解应用程序的结构:

struct Firebase: Codable {
    var name: String?
    var createTime, updateTime: String?
    var fields: FirebaseFields
}
现在,
FirebaseFields
也是另一个结构:

struct FirebaseFields: Codable {
    var emailID, lastName, firstName: String?
    var goalsRoutines: GoalsRoutines

    enum CodingKeys: String, CodingKey {
        case emailID = "email_id"
        case lastName = "last_name"
        case firstName = "first_name"
    }
}
类似地,
GoalsRoutines
也是一个结构

如上所述,我创建这些结构是为了遵循JSON对象的确切结构,即从Firebase API获得响应。因此,我访问如下字段:
Firebase.FirebaseFields.GoalsAndRoutines.whatever.is.my.Firebase.schema

我的
GoalsView.swift
是:

var body: some View {
    List{
        ...
        ...
    }.onAppear{
        FirebaseServices.getFirebaseData() {
         (data) in self.data = data   
        }
    }
}
func getFirebaseData(completion: @escaping ([Value]) -> ()) {
    guard let url = URL(string: "FIRESTORE URL HERE") else { return }
    URLSession.shared.dataTask(with: url) { (data, _, _) in
        let data = try! JSONDecoder().decode(Firebase.self, from: data!)
        DispatchQueue.main.async {
            completion(data.fields.goalsRoutines.arrayValue.values)
        }
    }.resume()
}
最后,在
firebaservices.swift
中,
func-getFirebaseData
是:

var body: some View {
    List{
        ...
        ...
    }.onAppear{
        FirebaseServices.getFirebaseData() {
         (data) in self.data = data   
        }
    }
}
func getFirebaseData(completion: @escaping ([Value]) -> ()) {
    guard let url = URL(string: "FIRESTORE URL HERE") else { return }
    URLSession.shared.dataTask(with: url) { (data, _, _) in
        let data = try! JSONDecoder().decode(Firebase.self, from: data!)
        DispatchQueue.main.async {
            completion(data.fields.goalsRoutines.arrayValue.values)
        }
    }.resume()
}
这就是我目前获取数据并在应用程序上显示的方式

我真的不知道如何在我的并发症上做同样的事情

非常感谢您的帮助