Jump to content

[swift] help with confusing error with seemingly no solution

hey,

 

i'm working on a weather app (its a beginner project) and my ContentView.swift is creating an error in the var body: some view saying: "The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions"

 

i've done some googling and nothing is working. pasted below is the entire contentview file, but if needed i can post the github repo i made.


import SwiftUI

import Combine



struct ContentView: View {

    @ObservedObject var networkManager = NetworkManager()



    var body: some View {

        ZStack{

            //MARK:BACKGROUND

            if let icon = networkManager.weather?.current.icon.rawValue{

                Image(icon)

                    .resizable()

                    .aspectRatio(contentMode: .fill)

            }

            //MARK: FOREGROUND

            VStack{

                Spacer()

                .frame(height:350)

                

                VStack(spacing:0){

                    //MARK: 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)

                    //MARK: High/Low

                    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()

                

                //MARK:OTHER DETAILS

                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()

                    //MARK:weekly view

                    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)

        }

    }



}

 

Main PC: the literature club machine

Intel I5 9600k @ 4.2 Ghz | MSI z390-a pro | G.Skill Trident Z RGB 32 GB 3000Mhz | Samsung 970 1TB | 2x Seagate barracuda 3.5" 2.5tb  | Thermaltake Floe Riing RGB 240 | MSI Ventus 2x black RTX 4060 TI 8gb | Be Quiet Pure Base 500DX

 

Daily drivers

Apple Iphone 12 | Apple Macbook Pro 2020 16gb | Ducky One 2 Skyline | Logitech G pro | Beryodynamic DT 990 PRO | Focusrite Scarlett 2i2 Gen 4

Link to post
Share on other sites

You have a typo here (hight) which may be part of the problem. Also if you try to build with the network manager stuff commented out then with it uncommented it might work. Other than that you can try to remove some elements from the single ZStack, and put them in another one as the error message states

 Spacer()
                    .frame(hight:100)

 

Link to post
Share on other sites

On 6/24/2021 at 12:23 AM, elpiop said:

You have a typo here (hight) which may be part of the problem. Also if you try to build with the network manager stuff commented out then with it uncommented it might work. Other than that you can try to remove some elements from the single ZStack, and put them in another one as the error message states



 Spacer()
                    .frame(hight:100)

 

sorry for late reply, will give that a try. thanks

Main PC: the literature club machine

Intel I5 9600k @ 4.2 Ghz | MSI z390-a pro | G.Skill Trident Z RGB 32 GB 3000Mhz | Samsung 970 1TB | 2x Seagate barracuda 3.5" 2.5tb  | Thermaltake Floe Riing RGB 240 | MSI Ventus 2x black RTX 4060 TI 8gb | Be Quiet Pure Base 500DX

 

Daily drivers

Apple Iphone 12 | Apple Macbook Pro 2020 16gb | Ducky One 2 Skyline | Logitech G pro | Beryodynamic DT 990 PRO | Focusrite Scarlett 2i2 Gen 4

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×