我需要在啓動應用程序時設置一些初始數據。我有這個名爲loadData()
的方法,它在裏面創建了幾個inviere,用於呼叫互聯網連接。我的代碼看起來是這樣的:通知哪些調用與可訪問性無關聯
func setup() {
if reachability.isReachable() {
// If there is connection, we setup the initial data
loadData()
} else {
//If there is no connection, wait for a notification
NSNotificationCenter.defaultCenter().addObserver(self, selector: "reachabilityChanged:", name: ReachabilityChangedNotification, object: nil)
do {
try reachability.startNotifier()
} catch {
print("Unable to start notifier")
}
}
}
func loadData() {
loadA()
loadB()
loadC()
..
loadZ()
}
func reachabilityChanged(note: NSNotification) {
if reachability!.isReachable() {
loadData()
reachability!.stopNotifier()
}
}
這讓我來處理,其中有開始loadData()
之前沒有任何聯繫的情況下。但是,如果連接丟失,例如,在loadC()
期間,我將無法添加通知,以便稍後可以加載缺失的數據。我怎樣才能做到這一點?
你想如何實現它?如何將所有項目添加到隊列中,以便可以暫停它並在它們之間添加依賴關係? – Wain
@有這樣的事情似乎是對的,我會怎麼做? – Matias
看看上次wwdc的nsoperation談話 – Wain