Swift : Compiler error when running with Xcode 14

Viewed 55

My code was working fine until I updated Xcode to v14. Now when running the code I have the following error : "The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions" The line is : "let task = defaultSession.dataTask(with: url) { [self] (data, response, error) in"

Strangely I have the same code in several functions and it's the only function getting an issue.

Would you have any idea to sort it out ?

I thank you in advance !

func LoadRecency2() {

    let url: URL = URL(string: "\(strGlobalPHPServer)listrecency.php?datedeb=\(strD)&datefin=\(strF)&rating=\(strR)")!
    print(url)

    let defaultSession = Foundation.URLSession(configuration: URLSessionConfiguration.default)

    let task = defaultSession.dataTask(with: url) { [self] (data, response, error) in
        
        if error != nil {
            print("Failed to download Recency data")
        }
        else {
            print("Recency data downloaded")
            do {
                let decoder = JSONDecoder()
                do {
                    myJson = try decoder.decode([RecencyData].self, from: data!)
                }
                catch {
                    print(error)
                }
            }
            DispatchQueue.main.async { [self] in
                arrayRecencyPk.removeAll()
                arrayRecencyDate.removeAll()
                arrayRecencyAtrJour.removeAll()
                arrayRecencyAtrNuit.removeAll()
                arrayRecencyNav1.removeAll()
                arrayRecencyNav2.removeAll()
                arrayRecencyNav3.removeAll()
                arrayRecencyNav4.removeAll()
                arrayRecencyAJ1.removeAll()
                arrayRecencyAJ2.removeAll()
                arrayRecencyAJ3.removeAll()
                arrayRecencyAJ4.removeAll()
                arrayRecencyAN1.removeAll()
                arrayRecencyAN2.removeAll()
                arrayRecencyAN3.removeAll()
                arrayRecencyAN4.removeAll()
                arrayRecencyACrating.removeAll()
                arrayRecencyACtype.removeAll()
                arrayRecencyACimmat.removeAll()
                arrayRecencyACcolor.removeAll()
                arrayRecencyACsim.removeAll()

                if myJson.count > 0 {
                    for intX in 0...myJson.count - 1 {
                        arrayRecencyPk.append(myJson[intX].Pk)
                        var dateTmp: Date = dateFormatterPHPtime.date(from: myJson[intX].DateMission)!
                        let strDateTmp = dateFormatterPHP.string(from: dateTmp)
                        dateTmp = dateFormatterPHP.date(from: strDateTmp)!
                        arrayRecencyDate.append(dateTmp)
                        arrayRecencyAtrJour.append(myJson[intX].AtrJour)
                        arrayRecencyAtrNuit.append(myJson[intX].AtrNuit)
                        arrayRecencyNav1.append(myJson[intX].Nav1)
                        arrayRecencyNav2.append(myJson[intX].Nav2)
                        arrayRecencyNav3.append(myJson[intX].Nav3)
                        arrayRecencyNav4.append(myJson[intX].Nav4)
                        arrayRecencyACrating.append(myJson[intX].ACrating)
                        arrayRecencyACtype.append(myJson[intX].ACtype)
                        arrayRecencyACimmat.append(myJson[intX].ACimmat)
                        arrayRecencyACcolor.append(myJson[intX].ACcolor)
                        arrayRecencyACsim.append(myJson[intX].ACsim)

                        let intAJ = Int(myJson[intX].AtrJour)
                        let intAJ4 = Int(intAJ! / 262144)
                        let intAJ3 = Int((intAJ! - (intAJ4 * 262144)) / 4096)
                        let intAJ2 = Int((intAJ! - (intAJ4 * 262144) - (intAJ3 * 4096)) / 64)
                        let intAJ1 = Int(intAJ! - (intAJ4 * 262144) - (intAJ3 * 4096) - (intAJ2 * 64))

                        arrayRecencyAJ1.append(intAJ1)
                        arrayRecencyAJ2.append(intAJ2)
                        arrayRecencyAJ3.append(intAJ3)
                        arrayRecencyAJ4.append(intAJ4)

                        let intAN = Int(myJson[intX].AtrNuit)
                        let intAN4 = Int(intAN! / 262144)
                        let intAN3 = Int((intAN! - (intAN4 * 262144)) / 4096)
                        let intAN2 = Int((intAN! - (intAN4 * 262144) - (intAN3 * 4096)) / 64)
                        let intAN1 = Int(intAN! - (intAN4 * 262144) - (intAN3 * 4096) - (intAN2 * 64))

                        arrayRecencyAN1.append(intAN1)
                        arrayRecencyAN2.append(intAN2)
                        arrayRecencyAN3.append(intAN3)
                        arrayRecencyAN4.append(intAN4)
                    }
                }
                lblDownloadStatus.text = "STEP 2/4 : Downloading Recency data..."
                LoadRecencyDev()
            }
        }
    }
    task.resume()
}
0 Answers
Related