恆定當我讀到的swift guide它說:The value of a constant doesn’t need to be known at compile time, but you must assign it a value exactly once.
聲明中迅速
我試着在REPL但沒有任何運氣:
let aConst;
aConst=23;
那麼如何聲明常數不設定初始值?
恆定當我讀到的swift guide它說:The value of a constant doesn’t need to be known at compile time, but you must assign it a value exactly once.
聲明中迅速
我試着在REPL但沒有任何運氣:
let aConst;
aConst=23;
那麼如何聲明常數不設定初始值?
例
let myConstant = getSomeValueFromMethod()
這是什麼意思,該值沒有在編譯時被稱爲...
你不能只是聲明一個常量而不分配它某種價值。編譯器需要知道常量會有某種價值。考慮下面的例子,其中常量「isTablet」是根據直到運行時才知道的變量計算的。
let isTablet = {
if (UIDevice.currentDevice().userInterfaceIdiom == .Pad) {
return true
} else {
return false
}
}()
Suthan的旁邊又如:
VAR someVar:NSString的
...
someVar = 「一些字符串」
讓someUnknownConstant = someVar
這很有道理! – sakhunzai