From 315ead606e52f451ffb4914af56617bee5ec3c9f Mon Sep 17 00:00:00 2001 From: Amir Abbas Mousavian Date: Sat, 17 Sep 2016 12:12:52 +0430 Subject: [PATCH] AnyObject casts changed to proper one according to data type --- .travis.yml | 2 +- Sources/DropboxHelper.swift | 16 ++++++++-------- Sources/LocalFileProvider.swift | 11 +++++------ 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1a36ae1..bd0eb92 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: objective-c -osx_image: xcode8.0 +osx_image: xcode8 script: - set pipefail - xcodebuild -project FileProvider.xcodeproj -scheme "FileProvider OSX" -sdk macosx | xcpretty diff --git a/Sources/DropboxHelper.swift b/Sources/DropboxHelper.swift index 6152391..040e109 100644 --- a/Sources/DropboxHelper.swift +++ b/Sources/DropboxHelper.swift @@ -40,11 +40,11 @@ internal extension DropboxFileProvider { let url: URL if let cursor = cursor { url = URL(string: "https://api.dropboxapi.com/2/files/list_folder/continue")! - requestDictionary["cursor"] = cursor as AnyObject? + requestDictionary["cursor"] = cursor as NSString? } else { url = URL(string: "https://api.dropboxapi.com/2/files/list_folder")! requestDictionary["path"] = correctPath(path) as NSString? - requestDictionary["recursive"] = recursive as AnyObject? + requestDictionary["recursive"] = recursive as NSNumber? } var request = URLRequest(url: url) request.httpMethod = "POST" @@ -89,7 +89,7 @@ internal extension DropboxFileProvider { requestDictionary["mode"] = (overwrite ? "overwrite" : "add") as NSString let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ssz" - requestDictionary["client_modified"] = dateFormatter.string(from: modifiedDate) as AnyObject? + requestDictionary["client_modified"] = dateFormatter.string(from: modifiedDate) as NSString var request = URLRequest(url: url) request.httpMethod = "POST" request.setValue("Bearer \(credential?.password ?? "")", forHTTPHeaderField: "Authorization") @@ -106,7 +106,7 @@ internal extension DropboxFileProvider { } completionHandler?(responseError ?? error) }) - var dic: [String: AnyObject] = ["type": operation.description as AnyObject] + var dic: [String: AnyObject] = ["type": operation.description as NSString] switch operation { case .create(path: let s): dic["source"] = s as NSString @@ -131,10 +131,10 @@ internal extension DropboxFileProvider { request.httpMethod = "POST" request.setValue("Bearer \(credential?.password ?? "")", forHTTPHeaderField: "Authorization") request.setValue("application/json", forHTTPHeaderField: "Content-Type") - var requestDictionary: [String: AnyObject] = ["path": startPath as AnyObject] - requestDictionary["query"] = query as AnyObject? - requestDictionary["start"] = start as AnyObject? - requestDictionary["max_results"] = maxResultPerPage as AnyObject? + var requestDictionary: [String: AnyObject] = ["path": startPath as NSString] + requestDictionary["query"] = query as NSString + requestDictionary["start"] = start as NSNumber + requestDictionary["max_results"] = maxResultPerPage as NSNumber request.httpBody = dictionaryToJSON(requestDictionary)?.data(using: String.Encoding.utf8) let task = session.dataTask(with: request, completionHandler: { (data, response, error) in var responseError: FileProviderDropboxError? diff --git a/Sources/LocalFileProvider.swift b/Sources/LocalFileProvider.swift index cc4943a..490117b 100644 --- a/Sources/LocalFileProvider.swift +++ b/Sources/LocalFileProvider.swift @@ -89,8 +89,8 @@ open class LocalFileProvider: FileProvider, FileProviderMonitor { open func storageProperties(completionHandler: (@escaping (_ total: Int64, _ used: Int64) -> Void)) { let dict = (try? FileManager.default.attributesOfFileSystem(forPath: baseURL?.path ?? "/")) - let totalSize = (dict?[FileAttributeKey.systemSize] as AnyObject).int64Value ?? -1; - let freeSize = (dict?[FileAttributeKey.systemFreeSize] as AnyObject).int64Value ?? 0; + let totalSize = (dict?[FileAttributeKey.systemSize] as? NSNumber)?.int64Value ?? -1; + let freeSize = (dict?[FileAttributeKey.systemFreeSize] as? NSNumber)?.int64Value ?? 0; completionHandler(totalSize, totalSize - freeSize) } @@ -442,7 +442,7 @@ internal class LocalFileProviderManagerDelegate: NSObject, FileManagerDelegate { } internal class LocalFolderMonitor { - fileprivate let source: DispatchSource + fileprivate let source: DispatchSourceFileSystemObject fileprivate let descriptor: CInt fileprivate let qq: DispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.default) fileprivate var state: Bool = false @@ -453,8 +453,7 @@ internal class LocalFolderMonitor { init(url: URL, handler: @escaping ()->Void) { self.url = url descriptor = open((url as NSURL).fileSystemRepresentation, O_EVTONLY) - - source = DispatchSource.makeFileSystemObjectSource(fileDescriptor: descriptor, eventMask: DispatchSource.FileSystemEvent.write, queue: qq) /*Migrator FIXME: Use DispatchSourceFileSystemObject to avoid the cast*/ as! DispatchSource + source = DispatchSource.makeFileSystemObjectSource(fileDescriptor: descriptor, eventMask: DispatchSource.FileSystemEvent.write, queue: qq) // Folder monitoring is recursive and deep. Monitoring a root folder may be very costly // We have a 0.2 second delay to ensure we wont call handler 1000s times when there is // a huge file operation. This ensures app will work smoothly while this 250 milisec won't @@ -464,7 +463,7 @@ internal class LocalFolderMonitor { return } self.monitoredTime = Date().timeIntervalSinceReferenceDate - DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(NSEC_PER_SEC) / 4) / Double(NSEC_PER_SEC), execute: { + DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.25, execute: { handler() }) }