有没有办法减少UserDefaults整数键值?
这是我的保存代码:
var highScore = UserDefaults().integer(forKey: "HIGHSCORE")
如何将此值减少一个固定的整数?
那么减少20等?
答案 0 :(得分:3)
首先,获取高分的旧值。然后,在最终保存新值之前进行算术运算:
double value;
datetime time; // - your values from file are here
int shift = iBarShift( _Symbol, 0, time );
ExtBufferCOT[shift] = value; /* probably need to fill buffer
of next candles too
if your chart timeframe
is smaller then frequency
of observations in the file
*/
答案 1 :(得分:0)
var highScore: Int {
get {
return Userdefaults.standard.integer(forKey: “highScore”)
} set {
Userdefaults.standard.set(newValue forKey: “highScore”)
}
}
可以通过
设置高分highScore = 5