2015-07-11 70 views
0

試圖將一些簡單的數字加在一起。在最後一行獲取「表達太複雜,無法在合理的時間內解決......」的錯誤。爲什麼?當然它不會變得更簡單?基本添加 - 表達式太複雜錯誤(Swift)

let year = calendar.component(.CalendarUnitYear, fromDate: inputGregorianDate) 
    let month = calendar.component(.CalendarUnitMonth, fromDate: inputGregorianDate) 
    let day = calendar.component(.CalendarUnitDay, fromDate: inputGregorianDate) 

    // Conversion Calulation 
    let AGR = year/100 
    let BGR = AGR/4 
    let CGR = 2 - AGR + BGR 
    var EGR = 0.00 
    if (month <= 2) { 
     EGR = 365.25 * Double(year + 4716) 
    } else { 
     EGR = 365.25 * Double(year + 4716); 
    } 
    let FGR = 30.6001 * Double(month + 1); 
    let dateJulian = Double(CGR + day + EGR + FGR - 1524.5) 

回答

1
// Conversion Calulation 
let AGR = Double(year)/100 
let BGR = AGR/4.0 
let CGR = 2.0 - AGR + BGR 
var EGR = 0.0 

// this conditional doesn't make any sense 
if (month <= 2) { 
    EGR = 365.25 * Double(year + 4716) 
} else { 
    EGR = 365.25 * Double(year + 4716) 
} 

let FGR = 30.6001 * Double(month + 1) 
let dateJulian = CGR + Double(day) + EGR + FGR - 1524.5 
+0

是謝謝你 - 但爲什麼不是編譯器給人一種雙/ INT /的Int32轉換錯誤呢?非常感謝,我將來會在源頭上將它們捆綁在一起。 –

+0

@EdwardHasted Swift以錯過主要錯誤信息而聞名 –

相關問題