私はコード戦で問題があります。エラーが発生しました:スウィフトで今年の世紀を返す関数を作成するにはどうすればよいですか?
declaration is only valid at file scope (extension Decimal)
誰かがこの問題を解決する方法を教えてください。 BTW私は入力として年と世紀を返す関数を作成しています。私のコードの推奨事項があれば教えてください。あなたが関数内で拡張を宣言することができないという事実のほかに
func centuryFromYear(year: Int) -> Int {
let centuryOtherStart = year/100
let centuryStart = Double(year/100)
let centuryEnd = round(centuryStart)
var wholeNumber : Bool
if wholeNumber == true {
return Int(centuryStart)
} else {
return Int(centuryEnd + 1)
}
extension Decimal {
var isWholeNumber: Bool {
wholeNumber = self.isZero || (self.isNormal && self.exponent >= 0)
}
}
}
エラーはクリアです。関数内に拡張を宣言することはできません。 – rmaddy