当加载应用程序时,我想知道我是否已将数据保存到磁盘。如果它被保存,我只是从磁盘加载,如果没有,我保存。
例如,我想使用Dim cel As Range, cel2 As Range
Dim lastRow As Long
lastRow = Cells(Rows.Count, 10).End(xlUp).Row
For Each cel In Range(Cells(1, 7), Cells(lastRow, 7))
For Each cel2 In Range(Cells(1, 10), Cells(lastRow, 10))
If cel2.Value = cel.Value Then
cel.Offset(0, 1).Value = cel2.Value
cel2.Value = ""
End If
Next cel2
Next cel
保存方法:
function createAssociativeArray(string, object) {
var parts = string.split('.');
var last = parts[parts.length - 1];
var tree = {};
var node = parts.slice(0, -1).reduce(function (memo, current) {
return (memo[current] = {});
}, tree);
node[last] = object;
return tree;
}
但我怎么知道我是否在NSUserDefaults.standardUserDefaults()
中保存了数据?我不想每次打开应用程序时保存,它也会覆盖我之前修改过的数据。
答案 0 :(得分:0)
您将如何做到这一点:
override func viewDidLoad() {
super.viewDidLoad()
if let savedPeople = NSUserDefaults.standardUserDefaults().objectForKey("people") {
// Use savedPeople based on your need
} else {
NSUserDefaults.standardUserDefaults().setObject(myArray, forKey: "people")
}
}