我有以下幾點:斯威夫特3定時事件
let processURLS = processingViewController()
Timer.scheduledTimer(timeInterval: 1,
target: self,
selector: #selector(processURLS.getURLsToSend),
userInfo: nil,
repeats: true)
當觸發這個事件,我收到以下錯誤,我不知道爲什麼這不起作用
2016- 11-09 14:47:00.504932 AcumenJLR [3414:905978] *終止應用 由於未捕獲的異常 'NSInvalidArgumentException',原因: ' - [AcumenJLR.homeViewController getURLsToSend]:無法識別選擇 發送到實例0x100d25c60' *第一擲調用堆棧:(0x1816721c0 0x1800ac55c 0x181679278 0x181676278 0x18157059c 0x18215c8f8 0x1816208f4 0x181620608 0x18161fec4 0x18161dac0 0x18154c048 0x182fd2198 0x1875372fc 0x187532034 0x100114620 0x1805305b8)的libC++ abi.dylib:與類型的 未捕獲的異常終止NSException
這裏是getURLsToSend方法
func getURLsToSend() {
//create a fetch request, telling it about the entity
let fetchRequest: NSFetchRequest<URLsToSend> = URLsToSend.fetchRequest()
let context = getContext()
do {
//Get results
let searchResults = try getContext().fetch(fetchRequest)
print ("num of results = \(searchResults.count)")
//You need to convert to NSManagedObject to use 'for' loops
for urls in searchResults as [NSManagedObject] {
//get the Key Value pairs (although there may be a better way to do that...
//print("\(urls.value(forKey: "url"))")
let currentURL = urls.value(forKey: "url")!
//print(urls.value(forKey: "url")!)
completeLoadAction(urlString: currentURL as! String) { code in
if (code == 200){
context.delete(urls)
}
}
}
} catch {
print("Error with request: \(error)")
}
這是因爲你沒有'在控制類 – alexburtnik
嘗試getURLsToSend'函數的引用保持你的'processURLS'然後更改選擇器'目標:自我,.processUrl選擇:#selector(getURLsToSend)' 。我認爲你的變量processURL已經從內存中刪除,所以選擇器不能執行。更新: –
但它似乎也是選擇器不正確,你必須使用*目標* ='processUrls'和*選擇器* ='getURLsToSend' –