AnyObject casts changed to proper one according to data type

This commit is contained in:
Amir Abbas Mousavian
2016-09-17 12:12:52 +04:30
parent d63e9c7f04
commit 315ead606e
3 changed files with 14 additions and 15 deletions
+1 -1
View File
@@ -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
+8 -8
View File
@@ -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?
+5 -6
View File
@@ -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()
})
}