属性“ body”的返回类型要求“ Box <Label <文本,图像>,某些视图>”符合“视图”

时间:2020-11-10 18:46:54

标签: swift swiftui

  • 静态方法“ buildBlock”要求“ Box
  • 属性“ body”的返回类型要求“ Box

这些是我一直遇到的错误,我一生无法解决。任何帮助将不胜感激!

Errors.

let torrent: RemoteTorrent

var body: some View {
    switch torrent.status {
        case let .downloading(_, _, _, downloadRate, uploadRate, eta):
        Box(label: Label("Statistics", systemImage: "speedometer")) {
            HStack {
                VStack(alignment: .leading) {
                    Label("Download Rate: \(ByteCountFormatter.humanReadableTransmissionSpeed(bytesPerSecond: downloadRate))", systemImage: "arrow.down.forward")
                    
                    Label("Upload Rate: \(ByteCountFormatter.humanReadableTransmissionSpeed(bytesPerSecond: uploadRate))", systemImage: "arrow.up.forward")
                    .padding(.top)
                    
                    if let humanReadableETA = eta.humanReadableDate {
                        Label("Time Remaining: \(humanReadableETA)", systemImage: "deskclock")
                        .padding(.top)
                    }
                }.padding(TorrentDetailsView.innerDetailPadding)
                Spacer()
            }.padding(.top)
        }
        
        case let .seeding(_, uploadRate, ratio, totalUploaded, secondsSeeding, _):
        Box(label: Label("Statistics", systemImage: "speedometer")) {
            HStack {
                VStack(alignment: .leading) {
                    Label("Upload Rate: \(ByteCountFormatter.humanReadableTransmissionSpeed(bytesPerSecond: uploadRate))", systemImage: "arrow.up.forward")
                    
                    if let totalUploaded = totalUploaded {
                        Label("Uploaded: \(ByteCountFormatter.humanReadableFileSize(bytes: totalUploaded)) (Ratio: \(String(format: "%.2f", ratio)))", systemImage: "arrow.up.to.line")
                        .padding(.top)
                    }
                    
                    if let humanReadableSeedingTime = secondsSeeding?.humanReadableDate {
                        Label("Seeding Time: \(humanReadableSeedingTime)", systemImage: "deskclock")
                        .padding(.top)
                    }
                }.padding(TorrentDetailsView.innerDetailPadding)
                Spacer()
            }.padding(.top)
        }
        
        default:
        EmptyView()
    }
}
}

0 个答案:

没有答案