我发现内存泄漏,但在swift 3中无法理解

时间:2017-02-28 07:50:15

标签: memory-leaks swift3 runtime-error

我在记忆中发现了以下问题。我无法理解。

error evaluating expression “(CAListenerProxy::DeviceAggregateNotification *)0x7cee3d60”: error: use of undeclared identifier 'CAListenerProxy'
error: expected expression

我使用了两个通知中心 - 一个用于将对象发送到另一个视图,另一个用于在另一个视图中删除一个包含对象的字典。

我的代码是:

//仅适用于下载视频的委托方法

extension WebViewController {
    func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) {

        // her i need to get the data from the movie which i download it so i can save it in the document directory
        if let fetchDataFromDownloadFile = try? Data(contentsOf: location) {
            // generate the fileName randamlly
            let createFileName = UUID().uuidString
            // generate object for save file
            let operationDocumentDirectory = OperationDocumentDirectory()
            operationDocumentDirectory.saveMovie(movieName: createFileName, data: fetchDataFromDownloadFile)
        }// end the if let for the fetch data from download file

        // her for fetch the download video object when i save it to set it to ni for free the memory
        if let fetchURL = downloadTask.originalRequest?.url {

            var fetchObject = operationObject?.dictionaryOfDownloadVideo?.removeValue(forKey: fetchURL)

            // for stop the downloadtask when finish download 
            if fetchObject?.videoURL == downloadTask.originalRequest?.url {
                downloadTask.cancel()
                fetchObject = nil
            }

            // for update the badge after finish download movie
            DispatchQueue.main.async {[weak self] in
                if let mySelf = self {
                    // set badge for nil if the objects zero
                    if operationObject.dictionaryOfDownloadVideo?.count == 0 {
                          self?.tabBarController?.viewControllers?[1].tabBarItem.badgeValue = nil
                    }else{
                // if the object not zero update the badge

                    mySelf.tabBarController?.viewControllers?[1].tabBarItem.badgeValue = "\(operationObject.dictionaryOfDownloadVideo!.count)"
                    }

                }// end the if for myself
            }// end the dispatchqueue.main

            // update the data in table view
            NotificationCenter.default.post(name: NOTIFICATION_UPDATE_TABLEVIEW, object: nil)

        }// end the fetch url

    }

//这个代码在另一个视图中用于在我当前正在下载电影时更新表视图

extension MovieDownloadingViewController {
    // data source
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as? DownloadingTableViewCell
        if let cell = cell {
            cell.movieObject = arrayOfObjects?[indexPath.row]
            cell.movieDeleteButton.tag = indexPath.row
            cell.movieDeleteButton.addTarget(self, action: #selector(self.deleteCurrentDownloadingMovie(sender:)), for: .touchUpInside)
        }
        return cell!
    }

    func deleteCurrentDownloadingMovie(sender:UIButton){
         displayAlertDeleteMovie(arrayOfObject: arrayOfObjects!, index: sender.tag)
    }

    func displayAlertDeleteMovie(arrayOfObject:[DownloadVideo],index:Int) {
        let alertController = UIAlertController(title: "Delete Movie", message: "Do You Want Delete Movie \(arrayOfObject[index].videoName)", preferredStyle: .actionSheet)
        let alertDelete = UIAlertAction(title: "Delete", style: .default) {[weak self] (alertAction:UIAlertAction) in


            var fetchObjectMovie = self?.arrayOfObjects?.remove(at: index)


            // set the notification for update the number of element in dict and array 
             NotificationCenter.default.post(name: NOTIFICATION_UPDATE_NUMBER_OF_ARRAY_DICT, object: fetchObjectMovie?.videoURL)
            if fetchObjectMovie != nil {

                fetchObjectMovie = nil
            }


              // update table view
             // self?.tableView.reloadData()

            // update the badge in the tab bar controller
            if operationObject.dictionaryOfDownloadVideo?.count == 0 {
                self?.tabBarController?.viewControllers?[1].tabBarItem.badgeValue = nil

            }else{
                self?.tabBarController?.viewControllers?[1].tabBarItem.badgeValue = "\(operationObject.dictionaryOfDownloadVideo!.count)"
            }

        }

        let alertCancel = UIAlertAction(title: "Cancel", style: .cancel) { [weak self](alertAction:UIAlertAction) in
            self?.dismiss(animated: true, completion: {})
        }
        alertController.addAction(alertDelete)
        alertController.addAction(alertCancel)
        present(alertController, animated: true, completion: nil)
    }

请任何帮助 非常感谢

0 个答案:

没有答案
相关问题