swift - Xcode 错误,似乎没有有效的解决方案/修复(编译器无法在合理的时间内对该表达式进行类型检查)
问题描述
背景:我正在上编程课,同时我试图转学,这样我就可以研究我对媒体的真正热情。对不起我草率的编程/缺乏知识。
我目前的评估是创建一个我几乎完成的可视天气应用程序。我唯一的问题是在第 15 行(我的正文视图所在的位置)创建了一个错误,显示为“编译器无法在合理的时间内对该表达式进行类型检查;尝试将表达式分解为不同的子表达式”
我已经尝试将表达式分解,但所有尝试都产生了随机错误。
我在运行 macOS catalina 10.15.4 的 2017 Macbook air 上运行 Xcode 版本 12.4。
有问题的代码如下,只是由于某些原因出现了一些格式错误(我实际上不确定是什么)
'''
导入 SwiftUI
进口组合
结构内容视图:查看{
@ObservedObject var networkManager = NetworkManager()
var body: some View {
ZStack{
//background
if let icon = networkManager.weather?.current.icon.rawValue{
Image(icon)
.resizable()
.aspectRatio(contentMode: .fill)
}
//foreground
VStack{
Spacer()
.frame(height:350)
VStack(spacing:0){
//current Temperature
HStack(alignment: .center){
if let currentIcon = networkManager.weather?.current.icon {
currentIcon.image
.font(.system(size: 40))
.foregroundColor(.primary)
}else {
Image(systemName: "arrow.clockwise.icloud")
.font(.system(size: 40))
}
if let currentTemp = networkManager.weather?.current.temperature {
Text("\(currentTemp, specifier: "%.1f")˚C")
.font(.custom("01 Digit", size: 60))
} else {
Text("--.-")
.font(.custom("01 Digit", size: 60))
}
}.frame(height:60)
//H/L
HStack{
VStack{
Text("HIGH")
.font(.custom("01 Digit", size: 15))
.foregroundColor(.red)
HStack{
if let myDailyHigh = networkManager.weather?.week.list.first!.maxTemperature {
Text("\(myDailyHigh, specifier: "%.0f")")
.font(.custom("01 Digit", size: 20))
.foregroundColor(.red)
} else {
Text("--.-˚")
.font(.custom("01 Digit", size: 20))
}
}
}
Divider()
VStack{
Text("LOW")
.font(.custom("01 Digit", size: 15))
.foregroundColor(.blue)
HStack{
if let myDailyLow = networkManager.weather?.week.list.first!.minTemperature {
Text("\(myDailyLow, specifier: "%.0f")")
.font(.custom("01 Digit", size: 20))
.foregroundColor(.blue)
} else {
Text("--.-˚")
.font(.custom("01 Digit", size: 20))
}
}
}
};.frame(height:40)
if let summary = networkManager.weather?.week.list.first!.summary {
Text(summary)
.font(.custom("01 Digit", size: 20))
.padding()
} else {
Text("Downloading weather data - please be patient, this is a slowass.")
.font(.custom("01 Digit", size: 20))
.padding()
}
}
Spacer()
//random
VStack{
HStack{
VStack{
Text("HUMIDITY")
.font(.custom("01 Digit", size: 12))
if let humidity = networkManager.weather?.week.list.first!.humidity {
Text("\(humidity*100, specifier: "%.0f")%")
.font(.custom("01 Digit", size: 20))
} else {
Text("--%")
.font(.custom("01 Digit", size: 20))
}
}
Divider()
VStack{
Text("DEW POINT")
.font(.custom("01 Digit", size: 12))
if let dewPoint = networkManager.weather?.week.list.first!.dewPoint {
Text("\(dewPoint, specifier: "%.0f")˚C")
.font(.custom("01 Digit", size: 20))
} else {
Text("--˚")
.font(.custom("01 Digit", size: 20))
}
}
Divider()
VStack{
Text("PRESSURE")
.font(.custom("01 Digit", size: 12))
if let pressure = networkManager.weather?.week.list.first!.pressure{
Text("\(pressure, specifier: "%.1f") hPa")
.font(.custom("01 Digit", size: 17.5))
} else {
Text("--.- hPa")
.font(.custom("01 Digit", size: 17.5))
}
}
Divider()
VStack{
Text("WIND SPEED")
.font(.custom("01 Digit", size: 12))
if let windSpeed = networkManager.weather?.week.list.first!.windSpeed {
Text("\(windSpeed, specifier: "%.1f") Km/h")
.font(.custom("01 Digit", size: 17.5))
} else {
Text("-.- Km/h")
.font(.custom("01 Digit", size: 17.5))
}
}
Divider()
VStack{
Text("RAIN")
.font(.custom("01 Digit", size: 12))
if let rain = networkManager.weather?.week.list.first!.precipProbability {
Text("\(rain, specifier: "%.0f")%")
.font(.custom("01 Digit", size: 20))
} else {
Text("--%")
.font(.custom("01 Digit", size: 20))
}
}
}
.padding(.init(top: 10.0, leading: 10.0, bottom: 10.0, trailing: 10.0))
.background(Color(.white).opacity(0.1))
.cornerRadius(10)
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(Color.secondary, lineWidth: 1)
)
Divider()
//Weekly view at bot
HStack{
ForEach (1..<8) {index in
VStack{
//
if let currentIcon = networkManager.weather?.week.list[index].icon {
currentIcon.image
}else {
Image(systemName: "arrow.clockwise.icloud")
}
//
Text("\(weekday(from: Date(), index:index))")
.font(.custom("01 Digit", size: 10))
HStack{
if let currentMax = networkManager.weather?.week.list[index].maxTemperature {
Text("\(currentMax, specifier:"%.0f")˚")
.font(.custom("01 Digit", size: 14))
.foregroundColor(.red)
} else {
Text("--˚")
.font(.custom("01 Digit", size: 14))
}
if let currentMin = networkManager.weather?.week.list[index].minTemperature {
Text("\(currentMin, specifier:"%.0f")˚")
.font(.custom("01 Digit", size: 14))
.foregroundColor(.blue)
} else {
Text("--˚")
.font(.custom("01 Digit", size: 14))
}
}
}.frame(width:50)
.padding(.init(top: 10.0, leading: 1, bottom: 10.0, trailing: 1.0))
.background(Color(.white).opacity(0.1))
.cornerRadius(10)
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(Color.secondary, lineWidth: 1)
)
}
}
Spacer()
.frame(height:120)
}
Spacer()
.frame(hight:100)
Image("DarkSky")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(height:120)
}
}
} } '''
解决方案
推荐阅读
- android - 如何在可穿戴应用的 xml 文件中添加滚动视图?
- flutter - TextInput中的白名单正双
- sql - 从查询中排除重复的产品
- javascript - JQuery delete older rows after threshold from jsp generated datatable
- python - 如何在本地磁盘中使用轮子更新 docker?
- localhost - firebase 服务,用于托管的模拟器端口?
- vue.js - Vuex商店更改时如何刷新视图?
- sql - 如何在列中获取唯一值但向我的查询添加更多列
- laravel - 有没有办法可以在 Laravel 的 API 路由中访问经过身份验证的用户信息?
- r - 按特定顺序折叠列值并将缺失值保留为 R 中的 NA