http://git-wip-us.apache.org/repos/asf/usergrid-swift/blob/b022377f/Source/UsergridAsset.swift ---------------------------------------------------------------------- diff --git a/Source/UsergridAsset.swift b/Source/UsergridAsset.swift index 9353ec1..93c88c7 100644 --- a/Source/UsergridAsset.swift +++ b/Source/UsergridAsset.swift @@ -32,13 +32,13 @@ import MobileCoreServices #endif /// The progress block used in `UsergridAsset` are being uploaded or downloaded. -public typealias UsergridAssetRequestProgress = (bytesFinished:Int64, bytesExpected: Int64) -> Void +public typealias UsergridAssetRequestProgress = (_ bytesFinished:Int64, _ bytesExpected: Int64) -> Void /// The completion block used in `UsergridAsset` are finished uploading. -public typealias UsergridAssetUploadCompletion = (asset:UsergridAsset?, response: UsergridResponse) -> Void +public typealias UsergridAssetUploadCompletion = (_ asset:UsergridAsset?, _ response: UsergridResponse) -> Void /// The completion block used in `UsergridAsset` are finished downloading. -public typealias UsergridAssetDownloadCompletion = (asset:UsergridAsset?, error: UsergridResponseError?) -> Void +public typealias UsergridAssetDownloadCompletion = (_ asset:UsergridAsset?, _ error: UsergridResponseError?) -> Void /** As Usergrid supports storing binary assets, the SDKs are designed to make uploading assets easier and more robust. Attaching, uploading, and downloading assets is handled by the `UsergridEntity` class. @@ -55,7 +55,7 @@ public class UsergridAsset: NSObject, NSCoding { public let filename: String /// Binary representation of the asset's data. - public let data: NSData + public let data: Data /// A representation of the folder location the asset was loaded from, if it was provided in the initialization. public let originalLocation: String? @@ -64,7 +64,7 @@ public class UsergridAsset: NSObject, NSCoding { public var contentType: String /// The content length of the assets data. - public var contentLength: Int { return self.data.length } + public var contentLength: Int { return self.data.count } // MARK: - Initialization - @@ -78,7 +78,7 @@ public class UsergridAsset: NSObject, NSCoding { - returns: A new instance of `UsergridAsset`. */ - public init(filename:String? = UsergridAsset.DEFAULT_FILE_NAME, data:NSData, originalLocation:String? = nil, contentType:String) { + public init(filename:String? = UsergridAsset.DEFAULT_FILE_NAME, data:Data, originalLocation:String? = nil, contentType:String) { self.filename = filename ?? UsergridAsset.DEFAULT_FILE_NAME self.data = data self.originalLocation = originalLocation @@ -95,18 +95,18 @@ public class UsergridAsset: NSObject, NSCoding { - returns: A new instance of `UsergridAsset` if the data can be gathered from the passed in `UIImage`, otherwise nil. */ - public convenience init?(filename:String? = UsergridAsset.DEFAULT_FILE_NAME, image:UIImage, imageContentType:UsergridImageContentType = .Png) { - var imageData: NSData? + public convenience init?(filename:String? = UsergridAsset.DEFAULT_FILE_NAME, image:UIImage, imageContentType:UsergridImageContentType = .png) { + var imageData: Data? switch(imageContentType) { - case .Png : + case .png : imageData = UIImagePNGRepresentation(image) - case .Jpeg : + case .jpeg : imageData = UIImageJPEGRepresentation(image, 1.0) } if let assetData = imageData { self.init(filename:filename,data:assetData,contentType:imageContentType.stringValue) } else { - self.init(filename:"",data:NSData(),contentType:"") + self.init(filename:"",data:Data(),contentType:"") return nil } } @@ -121,22 +121,22 @@ public class UsergridAsset: NSObject, NSCoding { - returns: A new instance of `UsergridAsset` if the data can be gathered from the passed in `NSURL`, otherwise nil. */ - public convenience init?(filename:String? = UsergridAsset.DEFAULT_FILE_NAME, fileURL:NSURL, contentType:String? = nil) { - if fileURL.fileURL, let assetData = NSData(contentsOfURL: fileURL) { + public convenience init?(filename:String? = UsergridAsset.DEFAULT_FILE_NAME, fileURL:URL, contentType:String? = nil) { + if fileURL.isFileURL, let assetData = try? Data(contentsOf: fileURL) { var fileNameToUse = filename - if fileNameToUse != UsergridAsset.DEFAULT_FILE_NAME, let inferredFileName = fileURL.lastPathComponent { - fileNameToUse = inferredFileName + if fileNameToUse != UsergridAsset.DEFAULT_FILE_NAME, !fileURL.lastPathComponent.isEmpty { + fileNameToUse = fileURL.lastPathComponent } if let fileContentType = contentType ?? UsergridAsset.MIMEType(fileURL) { self.init(filename:fileNameToUse,data:assetData,originalLocation:fileURL.absoluteString,contentType:fileContentType) } else { print("Usergrid Error: Failed to imply content type of the asset.") - self.init(filename:"",data:NSData(),contentType:"") + self.init(filename:"",data:Data(),contentType:"") return nil } } else { print("Usergrid Error: fileURL parameter must be a file URL.") - self.init(filename:"",data:NSData(),contentType:"") + self.init(filename:"",data:Data(),contentType:"") return nil } } @@ -151,21 +151,21 @@ public class UsergridAsset: NSObject, NSCoding { - returns: A decoded `UsergridUser` object. */ required public init?(coder aDecoder: NSCoder) { - guard let filename = aDecoder.decodeObjectForKey("filename") as? String, - let assetData = aDecoder.decodeObjectForKey("data") as? NSData, - let contentType = aDecoder.decodeObjectForKey("contentType") as? String + guard let filename = aDecoder.decodeObject(forKey: "filename") as? String, + let assetData = aDecoder.decodeObject(forKey: "data") as? Data, + let contentType = aDecoder.decodeObject(forKey: "contentType") as? String else { self.filename = "" self.contentType = "" self.originalLocation = nil - self.data = NSData() + self.data = Data() super.init() return nil } self.filename = filename self.data = assetData self.contentType = contentType - self.originalLocation = aDecoder.decodeObjectForKey("originalLocation") as? String + self.originalLocation = aDecoder.decodeObject(forKey: "originalLocation") as? String super.init() } @@ -174,16 +174,17 @@ public class UsergridAsset: NSObject, NSCoding { - parameter aCoder: The encoder. */ - public func encodeWithCoder(aCoder: NSCoder) { - aCoder.encodeObject(self.filename, forKey: "filename") - aCoder.encodeObject(self.data, forKey: "data") - aCoder.encodeObject(self.contentType, forKey: "contentType") - aCoder.encodeObject(self.originalLocation, forKey: "originalLocation") + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.filename, forKey: "filename") + aCoder.encode(self.data, forKey: "data") + aCoder.encode(self.contentType, forKey: "contentType") + aCoder.encode(self.originalLocation, forKey: "originalLocation") } - private static func MIMEType(fileURL: NSURL) -> String? { - if let pathExtension = fileURL.pathExtension { - if let UTIRef = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension, nil) { + private static func MIMEType(_ fileURL: URL) -> String? { + let pathExtension = fileURL.pathExtension + if !pathExtension.isEmpty { + if let UTIRef = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension as CFString, nil) { let UTI = UTIRef.takeUnretainedValue() UTIRef.release() if let MIMETypeRef = UTTypeCopyPreferredTagWithClass(UTI, kUTTagClassMIMEType) { @@ -195,4 +196,4 @@ public class UsergridAsset: NSObject, NSCoding { } return nil } -} \ No newline at end of file +}
http://git-wip-us.apache.org/repos/asf/usergrid-swift/blob/b022377f/Source/UsergridAssetRequestWrapper.swift ---------------------------------------------------------------------- diff --git a/Source/UsergridAssetRequestWrapper.swift b/Source/UsergridAssetRequestWrapper.swift index d715652..37b5288 100644 --- a/Source/UsergridAssetRequestWrapper.swift +++ b/Source/UsergridAssetRequestWrapper.swift @@ -26,23 +26,23 @@ import Foundation -typealias UsergridAssetRequestWrapperCompletionBlock = (requestWrapper:UsergridAssetRequestWrapper) -> Void +typealias UsergridAssetRequestWrapperCompletionBlock = (_ requestWrapper:UsergridAssetRequestWrapper) -> Void final class UsergridAssetRequestWrapper { - weak var session: NSURLSession? - let sessionTask: NSURLSessionTask + weak var session: URLSession? + let sessionTask: URLSessionTask - var response: NSURLResponse? - var responseData: NSData? + var response: URLResponse? + var responseData: Data? var error: NSError? var progress: UsergridAssetRequestProgress? let completion: UsergridAssetRequestWrapperCompletionBlock - init(session:NSURLSession?, sessionTask:NSURLSessionTask, progress:UsergridAssetRequestProgress?, completion:UsergridAssetRequestWrapperCompletionBlock) { + init(session:URLSession?, sessionTask:URLSessionTask, progress:UsergridAssetRequestProgress?, completion:UsergridAssetRequestWrapperCompletionBlock) { self.session = session self.sessionTask = sessionTask self.progress = progress self.completion = completion } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/usergrid-swift/blob/b022377f/Source/UsergridAuth.swift ---------------------------------------------------------------------- diff --git a/Source/UsergridAuth.swift b/Source/UsergridAuth.swift index e87e9c1..228a4f4 100644 --- a/Source/UsergridAuth.swift +++ b/Source/UsergridAuth.swift @@ -27,10 +27,10 @@ import Foundation /// The completion block used in `UsergridAppAuth` authentication methods. -public typealias UsergridAppAuthCompletionBlock = (auth:UsergridAppAuth?, error: UsergridResponseError?) -> Void +public typealias UsergridAppAuthCompletionBlock = (_ auth:UsergridAppAuth?, _ error: UsergridResponseError?) -> Void /// The completion block used in `UsergridUserAuth` authentication methods. -public typealias UsergridUserAuthCompletionBlock = (auth:UsergridUserAuth?, user:UsergridUser?, error: UsergridResponseError?) -> Void +public typealias UsergridUserAuthCompletionBlock = (_ auth:UsergridUserAuth?, _ user:UsergridUser?, _ error: UsergridResponseError?) -> Void /** The `UsergridAuth` class functions to create and store authentication information used by Usergrid. @@ -45,7 +45,7 @@ public class UsergridAuth : NSObject, NSCoding { public var accessToken : String? /// The expires at date, if this `UsergridAuth` was authorized successfully and their was a expires in time stamp within the token response. - public var expiry : NSDate? + public var expiry : Date? /// Determines if an access token exists. public var hasToken: Bool { return self.accessToken != nil } @@ -68,7 +68,7 @@ public class UsergridAuth : NSObject, NSCoding { } /// The credentials dictionary. Subclasses must override this method and provide an actual dictionary containing the credentials to send with requests. - var credentialsJSONDict: [String:AnyObject] { + var credentialsJSONDict: [String:Any] { return [:] } @@ -79,7 +79,7 @@ public class UsergridAuth : NSObject, NSCoding { - returns: A new instance of `UsergridAuth`. */ - override private init() { + override fileprivate init() { super.init() } @@ -91,7 +91,7 @@ public class UsergridAuth : NSObject, NSCoding { - returns: A new instance of `UsergridAuth` */ - public init(accessToken:String, expiry:NSDate? = nil) { + public init(accessToken:String, expiry:Date? = nil) { self.usingToken = true self.accessToken = accessToken self.expiry = expiry @@ -107,8 +107,8 @@ public class UsergridAuth : NSObject, NSCoding { - returns: A decoded `UsergridAuth` object. */ required public init?(coder aDecoder: NSCoder) { - self.accessToken = aDecoder.decodeObjectForKey("accessToken") as? String - self.expiry = aDecoder.decodeObjectForKey("expiry") as? NSDate + self.accessToken = aDecoder.decodeObject(forKey: "accessToken") as? String + self.expiry = aDecoder.decodeObject(forKey: "expiry") as? Date } /** @@ -116,12 +116,12 @@ public class UsergridAuth : NSObject, NSCoding { - parameter aCoder: The encoder. */ - public func encodeWithCoder(aCoder: NSCoder) { + public func encode(with aCoder: NSCoder) { if let accessToken = self.accessToken { - aCoder.encodeObject(accessToken, forKey: "accessToken") + aCoder.encode(accessToken, forKey: "accessToken") } if let expiresAt = self.expiry { - aCoder.encodeObject(expiresAt, forKey: "expiry") + aCoder.encode(expiresAt, forKey: "expiry") } } @@ -148,7 +148,7 @@ public class UsergridUserAuth : UsergridAuth { private let password: String /// The credentials dictionary constructed with the `UsergridUserAuth`'s `username` and `password`. - override var credentialsJSONDict: [String:AnyObject] { + override var credentialsJSONDict: [String:Any] { return ["grant_type":"password", "username":self.username, "password":self.password] @@ -180,8 +180,8 @@ public class UsergridUserAuth : UsergridAuth { - returns: A decoded `UsergridUserAuth` object. */ required public init?(coder aDecoder: NSCoder) { - guard let username = aDecoder.decodeObjectForKey("username") as? String, - password = aDecoder.decodeObjectForKey("password") as? String + guard let username = aDecoder.decodeObject(forKey: "username") as? String, + let password = aDecoder.decodeObject(forKey: "password") as? String else { self.username = "" self.password = "" @@ -199,10 +199,10 @@ public class UsergridUserAuth : UsergridAuth { - parameter aCoder: The encoder. */ - override public func encodeWithCoder(aCoder: NSCoder) { - aCoder.encodeObject(self.username, forKey: "username") - aCoder.encodeObject(self.password, forKey: "password") - super.encodeWithCoder(aCoder) + override public func encode(with aCoder: NSCoder) { + aCoder.encode(self.username, forKey: "username") + aCoder.encode(self.password, forKey: "password") + super.encode(with: aCoder) } } @@ -218,7 +218,7 @@ public class UsergridAppAuth : UsergridAuth { private let clientSecret: String /// The credentials dictionary constructed with the `UsergridAppAuth`'s `clientId` and `clientSecret`. - override var credentialsJSONDict: [String:AnyObject] { + override var credentialsJSONDict: [String:Any] { return ["grant_type":"client_credentials", "client_id":self.clientId, "client_secret":self.clientSecret] @@ -250,8 +250,8 @@ public class UsergridAppAuth : UsergridAuth { - returns: A decoded `UsergridAppAuth` object. */ required public init?(coder aDecoder: NSCoder) { - guard let clientId = aDecoder.decodeObjectForKey("clientId") as? String, - let clientSecret = aDecoder.decodeObjectForKey("clientSecret") as? String + guard let clientId = aDecoder.decodeObject(forKey: "clientId") as? String, + let clientSecret = aDecoder.decodeObject(forKey: "clientSecret") as? String else { self.clientId = "" self.clientSecret = "" @@ -268,9 +268,9 @@ public class UsergridAppAuth : UsergridAuth { - parameter aCoder: The encoder. */ - override public func encodeWithCoder(aCoder: NSCoder) { - aCoder.encodeObject(self.clientId, forKey: "clientId") - aCoder.encodeObject(self.clientSecret, forKey: "clientSecret") - super.encodeWithCoder(aCoder) + override public func encode(with aCoder: NSCoder) { + aCoder.encode(self.clientId, forKey: "clientId") + aCoder.encode(self.clientSecret, forKey: "clientSecret") + super.encode(with: aCoder) } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/usergrid-swift/blob/b022377f/Source/UsergridClient.swift ---------------------------------------------------------------------- diff --git a/Source/UsergridClient.swift b/Source/UsergridClient.swift index 2b3eb6b..81fe3a6 100644 --- a/Source/UsergridClient.swift +++ b/Source/UsergridClient.swift @@ -143,7 +143,7 @@ public class UsergridClient: NSObject, NSCoding { - returns: A decoded `UsergridClient` object. */ public required init?(coder aDecoder: NSCoder) { - guard let config = aDecoder.decodeObjectForKey("config") as? UsergridClientConfig + guard let config = aDecoder.decodeObject(forKey: "config") as? UsergridClientConfig else { self.config = UsergridClientConfig(orgId: "", appId: "") super.init() @@ -153,7 +153,7 @@ public class UsergridClient: NSObject, NSCoding { self.config = config super.init() - if let currentUser = aDecoder.decodeObjectForKey("currentUser") as? UsergridUser { + if let currentUser = aDecoder.decodeObject(forKey: "currentUser") as? UsergridUser { self.currentUser = currentUser } else { if persistCurrentUserInKeychain { @@ -168,9 +168,9 @@ public class UsergridClient: NSObject, NSCoding { - parameter aCoder: The encoder. */ - public func encodeWithCoder(aCoder: NSCoder) { - aCoder.encodeObject(self.config, forKey: "config") - aCoder.encodeObject(self.currentUser, forKey: "currentUser") + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.config, forKey: "config") + aCoder.encode(self.currentUser, forKey: "currentUser") } // MARK: - Device Registration/Push Notifications - @@ -182,7 +182,7 @@ public class UsergridClient: NSObject, NSCoding { - parameter notifierID: The Usergrid notifier ID. - parameter completion: The completion block. */ - public func applyPushToken(pushToken: NSData, notifierID: String, completion: UsergridResponseCompletion? = nil) { + public func applyPushToken(_ pushToken: Data, notifierID: String, completion: UsergridResponseCompletion? = nil) { self.applyPushToken(UsergridDevice.sharedDevice, pushToken: pushToken, notifierID: notifierID, completion: completion) } @@ -194,13 +194,13 @@ public class UsergridClient: NSObject, NSCoding { - parameter notifierID: The Usergrid notifier ID. - parameter completion: The completion block. */ - public func applyPushToken(device: UsergridDevice, pushToken: NSData, notifierID: String, completion: UsergridResponseCompletion? = nil) { + public func applyPushToken(_ device: UsergridDevice, pushToken: Data, notifierID: String, completion: UsergridResponseCompletion? = nil) { device.applyPushToken(pushToken, notifierID: notifierID) self.PUT("devices", jsonBody: device.jsonObjectValue) { (response) in if let responseEntity = response.entity { device.copyInternalsFromEntity(responseEntity) } - completion?(response: response) + completion?(response) } } @@ -226,17 +226,17 @@ public class UsergridClient: NSObject, NSCoding { self.tempAuth = nil } else { switch(self.authMode) { - case .User: - if let userAuth = self.userAuth where userAuth.isValid { + case .user: + if let userAuth = self.userAuth , userAuth.isValid { usergridAuth = userAuth } break - case .App: - if let appAuth = self.appAuth where appAuth.isValid { + case .app: + if let appAuth = self.appAuth , appAuth.isValid { usergridAuth = appAuth } break - case .None: + case .none: usergridAuth = nil break } @@ -253,7 +253,7 @@ public class UsergridClient: NSObject, NSCoding { - returns: `Self` */ - public func usingAuth(auth:UsergridAuth) -> Self { + public func usingAuth(_ auth:UsergridAuth) -> Self { self.tempAuth = auth return self } @@ -267,7 +267,7 @@ public class UsergridClient: NSObject, NSCoding { - returns: `Self` */ - public func usingToken(token:String) -> Self { + public func usingToken(_ token:String) -> Self { self.tempAuth = UsergridAuth(accessToken: token) return self } @@ -277,11 +277,11 @@ public class UsergridClient: NSObject, NSCoding { - parameter completion: The completion block that will be called after authentication has completed. */ - public func authenticateApp(completion: UsergridAppAuthCompletionBlock? = nil) { + public func authenticateApp(_ completion: UsergridAppAuthCompletionBlock? = nil) { guard let appAuth = self.appAuth else { let error = UsergridResponseError(errorName: "Invalid UsergridAppAuth.", errorDescription: "UsergridClient's appAuth is nil.") - completion?(auth: nil, error: error) + completion?(nil, error) return } self.authenticateApp(appAuth, completion: completion) @@ -293,16 +293,16 @@ public class UsergridClient: NSObject, NSCoding { - parameter auth: The `UsergridAppAuth` that will be authenticated. - parameter completion: The completion block that will be called after authentication has completed. */ - public func authenticateApp(appAuth: UsergridAppAuth, completion: UsergridAppAuthCompletionBlock? = nil) { - let request = UsergridRequest(method: .Post, + public func authenticateApp(_ appAuth: UsergridAppAuth, completion: UsergridAppAuthCompletionBlock? = nil) { + let request = UsergridRequest(method: .post, baseUrl: self.clientAppURL, paths: ["token"], auth: self.authForRequests(), - jsonBody: appAuth.credentialsJSONDict) + jsonBody: appAuth.credentialsJSONDict as Any?) _requestManager.performAppAuthRequest(appAuth, request: request) { [weak self] (auth,error) in self?.appAuth = auth - completion?(auth: auth, error: error) + completion?(auth, error) } } @@ -312,7 +312,7 @@ public class UsergridClient: NSObject, NSCoding { - parameter auth: The `UsergridUserAuth` that will be authenticated. - parameter completion: The completion block that will be called after authentication has completed. */ - public func authenticateUser(userAuth: UsergridUserAuth, completion: UsergridUserAuthCompletionBlock? = nil) { + public func authenticateUser(_ userAuth: UsergridUserAuth, completion: UsergridUserAuthCompletionBlock? = nil) { self.authenticateUser(userAuth, setAsCurrentUser:true, completion:completion) } @@ -323,17 +323,17 @@ public class UsergridClient: NSObject, NSCoding { - parameter setAsCurrentUser: If the authenticated user should be set as the `UsergridClient.currentUser`. - parameter completion: The completion block that will be called after authentication has completed. */ - public func authenticateUser(userAuth: UsergridUserAuth, setAsCurrentUser: Bool, completion: UsergridUserAuthCompletionBlock? = nil) { - let request = UsergridRequest(method: .Post, + public func authenticateUser(_ userAuth: UsergridUserAuth, setAsCurrentUser: Bool, completion: UsergridUserAuthCompletionBlock? = nil) { + let request = UsergridRequest(method: .post, baseUrl: self.clientAppURL, paths: ["token"], auth: self.authForRequests(), - jsonBody: userAuth.credentialsJSONDict) + jsonBody: userAuth.credentialsJSONDict as Any?) _requestManager.performUserAuthRequest(userAuth, request: request) { [weak self] (auth,user,error) in if setAsCurrentUser { self?.currentUser = user } - completion?(auth: auth, user: user, error: error) + completion?(auth, user, error) } } @@ -345,21 +345,21 @@ public class UsergridClient: NSObject, NSCoding { - parameter new: The new password. - parameter completion: The optional completion block. */ - public func resetPassword(user: UsergridUser, old:String, new:String, completion:UsergridUserResetPasswordCompletion? = nil) { + public func resetPassword(_ user: UsergridUser, old:String, new:String, completion:UsergridUserResetPasswordCompletion? = nil) { guard let usernameOrEmail = user.usernameOrEmail else { - completion?(error: UsergridResponseError(errorName: "Error resetting password.", errorDescription: "The UsergridUser object must contain a valid username or email to reset the password."), didSucceed: false) + completion?(UsergridResponseError(errorName: "Error resetting password.", errorDescription: "The UsergridUser object must contain a valid username or email to reset the password."), false) return } - let request = UsergridRequest(method: .Put, + let request = UsergridRequest(method: .put, baseUrl: self.clientAppURL, paths: ["users",usernameOrEmail,"password"], auth: self.authForRequests(), jsonBody:["oldpassword":old,"newpassword":new]) _requestManager.performRequest(request, completion: { (response) -> Void in - completion?(error: response.error, didSucceed: response.statusCode == 200) + completion?(response.error, response.statusCode == 200) }) } @@ -368,11 +368,11 @@ public class UsergridClient: NSObject, NSCoding { - parameter completion: The completion block that will be called after logout has completed. */ - public func logoutCurrentUser(completion:UsergridResponseCompletion? = nil) { + public func logoutCurrentUser(_ completion:UsergridResponseCompletion? = nil) { guard let uuidOrUsername = self.currentUser?.uuidOrUsername, let token = self.currentUser?.auth?.accessToken else { - completion?(response:UsergridResponse(client: self, errorName: "Logout Failed.", errorDescription: "UsergridClient's currentUser is not valid.")) + completion?(UsergridResponse(client: self, errorName: "Logout Failed.", errorDescription: "UsergridClient's currentUser is not valid.")) return } @@ -384,7 +384,7 @@ public class UsergridClient: NSObject, NSCoding { - parameter completion: The completion block that will be called after logout has completed. */ - public func logoutUserAllTokens(uuidOrUsername:String, completion:UsergridResponseCompletion? = nil) { + public func logoutUserAllTokens(_ uuidOrUsername:String, completion:UsergridResponseCompletion? = nil) { self.logoutUser(uuidOrUsername, token: nil, completion: completion) } @@ -395,7 +395,7 @@ public class UsergridClient: NSObject, NSCoding { - parameter completion: The completion block that will be called after logout has completed. */ - public func logoutUser(uuidOrUsername:String, token:String?, completion:UsergridResponseCompletion? = nil) { + public func logoutUser(_ uuidOrUsername:String, token:String?, completion:UsergridResponseCompletion? = nil) { var paths = ["users",uuidOrUsername] var queryParams: [String: String]? if let accessToken = token { @@ -404,7 +404,7 @@ public class UsergridClient: NSObject, NSCoding { } else { paths.append("revoketokens") } - let request = UsergridRequest(method: .Put, + let request = UsergridRequest(method: .put, baseUrl: self.clientAppURL, paths: paths, auth: self.authForRequests(), @@ -417,7 +417,7 @@ public class UsergridClient: NSObject, NSCoding { self.currentUser = nil } } - completion?(response: response) + completion?(response) } } @@ -431,7 +431,7 @@ public class UsergridClient: NSObject, NSCoding { - parameter request: The `UsergridRequest` object to send. - parameter completion: The optional completion block that will be called once the request has completed. */ - public func sendRequest(request:UsergridRequest, completion:UsergridResponseCompletion? = nil) { + public func sendRequest(_ request:UsergridRequest, completion:UsergridResponseCompletion? = nil) { _requestManager.performRequest(request, completion: completion) } @@ -444,8 +444,8 @@ public class UsergridClient: NSObject, NSCoding { - parameter uuidOrName: The UUID or name of the `UsergridEntity`. - parameter completion: The optional completion block that will be called once the request has completed. */ - public func GET(type: String, uuidOrName: String, completion: UsergridResponseCompletion? = nil) { - let request = UsergridRequest(method: .Get, baseUrl: self.clientAppURL, paths: [type,uuidOrName], auth:self.authForRequests()) + public func GET(_ type: String, uuidOrName: String, completion: UsergridResponseCompletion? = nil) { + let request = UsergridRequest(method: .get, baseUrl: self.clientAppURL, paths: [type,uuidOrName], auth:self.authForRequests()) self.sendRequest(request, completion: completion) } @@ -455,8 +455,8 @@ public class UsergridClient: NSObject, NSCoding { - parameter type: The `UsergridEntity` type. - parameter completion: The optional completion block that will be called once the request has completed. */ - public func GET(type: String, completion: UsergridResponseCompletion? = nil) { - let request = UsergridRequest(method: .Get, baseUrl: self.clientAppURL, paths: [type], query: nil, auth: self.authForRequests()) + public func GET(_ type: String, completion: UsergridResponseCompletion? = nil) { + let request = UsergridRequest(method: .get, baseUrl: self.clientAppURL, paths: [type], query: nil, auth: self.authForRequests()) self.sendRequest(request, completion: completion) } @@ -466,14 +466,14 @@ public class UsergridClient: NSObject, NSCoding { - parameter query: The query to use when gathering `UsergridEntity` objects. - parameter queryCompletion: The optional completion block that will be called once the request has completed. */ - public func GET(query: UsergridQuery, queryCompletion: UsergridResponseCompletion? = nil) { + public func GET(_ query: UsergridQuery, queryCompletion: UsergridResponseCompletion? = nil) { guard let type = query.collectionName else { - queryCompletion?(response: UsergridResponse(client:self, errorName: "Query collection name missing.", errorDescription: "Query collection name is missing.")) + queryCompletion?(UsergridResponse(client:self, errorName: "Query collection name missing.", errorDescription: "Query collection name is missing.")) return } - let request = UsergridRequest(method: .Get, baseUrl: self.clientAppURL, paths: [type], query: query, auth: self.authForRequests()) + let request = UsergridRequest(method: .get, baseUrl: self.clientAppURL, paths: [type], query: query, auth: self.authForRequests()) self.sendRequest(request, completion: queryCompletion) } @@ -487,13 +487,13 @@ public class UsergridClient: NSObject, NSCoding { - parameter jsonBody: The valid JSON body dictionary to update the `UsergridEntity` with. - parameter completion: The optional completion block that will be called once the request has completed. */ - public func PUT(type: String, uuidOrName: String, jsonBody:[String:AnyObject], completion: UsergridResponseCompletion? = nil) { - let request = UsergridRequest(method: .Put, + public func PUT(_ type: String, uuidOrName: String, jsonBody:[String:Any], completion: UsergridResponseCompletion? = nil) { + let request = UsergridRequest(method: .put, baseUrl: self.clientAppURL, paths: [type,uuidOrName], auth: self.authForRequests(), - headers: UsergridRequest.JSON_CONTENT_TYPE_HEADER, - jsonBody: jsonBody) + headers: UsergridRequest.jsonHeaderContentType(), + jsonBody: jsonBody as Any?) self.sendRequest(request, completion: completion) } @@ -503,7 +503,7 @@ public class UsergridClient: NSObject, NSCoding { - parameter entity: The `UsergridEntity` to update. - parameter completion: The optional completion block that will be called once the request has completed. */ - public func PUT(entity: UsergridEntity, completion: UsergridResponseCompletion? = nil) { + public func PUT(_ entity: UsergridEntity, completion: UsergridResponseCompletion? = nil) { PUT(entity.type, jsonBody: entity.jsonObjectValue, completion: completion) } @@ -516,18 +516,18 @@ public class UsergridClient: NSObject, NSCoding { - parameter jsonBody: The valid JSON body dictionary to update the `UsergridEntity` with. - parameter completion: The optional completion block that will be called once the request has completed. */ - public func PUT(type: String, jsonBody:[String:AnyObject], completion: UsergridResponseCompletion? = nil) { - guard let uuidOrName = (jsonBody[UsergridEntityProperties.UUID.stringValue] ?? jsonBody[UsergridEntityProperties.Name.stringValue]) as? String + public func PUT(_ type: String, jsonBody:[String:Any], completion: UsergridResponseCompletion? = nil) { + guard let uuidOrName = (jsonBody[UsergridEntityProperties.uuid.stringValue] ?? jsonBody[UsergridEntityProperties.name.stringValue]) as? String else { - completion?(response: UsergridResponse(client:self, errorName: "jsonBody not valid.", errorDescription: "The `jsonBody` must contain a valid value for either `uuid` or `name`.")) + completion?(UsergridResponse(client:self, errorName: "jsonBody not valid.", errorDescription: "The `jsonBody` must contain a valid value for either `uuid` or `name`.")) return } - let request = UsergridRequest(method: .Put, + let request = UsergridRequest(method: .put, baseUrl: self.clientAppURL, paths: [type,uuidOrName], auth: self.authForRequests(), - headers: UsergridRequest.JSON_CONTENT_TYPE_HEADER, - jsonBody: jsonBody) + headers: UsergridRequest.jsonHeaderContentType(), + jsonBody: jsonBody as Any?) self.sendRequest(request, completion: completion) } @@ -540,19 +540,19 @@ public class UsergridClient: NSObject, NSCoding { - parameter jsonBody: The valid JSON body dictionary to update with. - parameter queryCompletion: The optional completion block that will be called once the request has completed. */ - public func PUT(query: UsergridQuery, jsonBody:[String:AnyObject], queryCompletion: UsergridResponseCompletion? = nil) { + public func PUT(_ query: UsergridQuery, jsonBody:[String:Any], queryCompletion: UsergridResponseCompletion? = nil) { guard let type = query.collectionName else { - queryCompletion?(response: UsergridResponse(client:self, errorName: "Query collection name invalid.", errorDescription: "Query is missing a collection name.")) + queryCompletion?(UsergridResponse(client:self, errorName: "Query collection name invalid.", errorDescription: "Query is missing a collection name.")) return } - let request = UsergridRequest(method: .Put, + let request = UsergridRequest(method: .put, baseUrl: self.clientAppURL, paths: [type], query: query, auth: self.authForRequests(), - headers: UsergridRequest.JSON_CONTENT_TYPE_HEADER, - jsonBody: jsonBody) + headers: UsergridRequest.jsonHeaderContentType(), + jsonBody: jsonBody as Any?) self.sendRequest(request, completion: queryCompletion) } @@ -563,13 +563,13 @@ public class UsergridClient: NSObject, NSCoding { - parameter entity: The `UsergridEntity` to create. - parameter completion: The optional completion block that will be called once the request has completed. */ - public func POST(entity:UsergridEntity, completion: UsergridResponseCompletion? = nil) { - let request = UsergridRequest(method: .Post, + public func POST(_ entity:UsergridEntity, completion: UsergridResponseCompletion? = nil) { + let request = UsergridRequest(method: .post, baseUrl: self.clientAppURL, paths: [entity.type], auth: self.authForRequests(), - headers: UsergridRequest.JSON_CONTENT_TYPE_HEADER, - jsonBody: entity.jsonObjectValue) + headers: UsergridRequest.jsonHeaderContentType(), + jsonBody: entity.jsonObjectValue as Any?) self.sendRequest(request, completion: completion) } @@ -581,10 +581,10 @@ public class UsergridClient: NSObject, NSCoding { - parameter entities: The `UsergridEntity` objects to create. - parameter entitiesCompletion: The optional completion block that will be called once the request has completed. */ - public func POST(entities:[UsergridEntity], entitiesCompletion: UsergridResponseCompletion? = nil) { + public func POST(_ entities:[UsergridEntity], entitiesCompletion: UsergridResponseCompletion? = nil) { guard let type = entities.first?.type else { - entitiesCompletion?(response: UsergridResponse(client:self, errorName: "No type found.", errorDescription: "The first entity in the array had no type found.")) + entitiesCompletion?(UsergridResponse(client:self, errorName: "No type found.", errorDescription: "The first entity in the array had no type found.")) return } POST(type, jsonBodies: entities.map { return ($0).jsonObjectValue }, completion: entitiesCompletion) @@ -597,13 +597,13 @@ public class UsergridClient: NSObject, NSCoding { - parameter jsonBody: The valid JSON body dictionary to use when creating the `UsergridEntity`. - parameter completion: The optional completion block that will be called once the request has completed. */ - public func POST(type: String, jsonBody:[String:AnyObject], completion: UsergridResponseCompletion? = nil) { - let request = UsergridRequest(method: .Post, + public func POST(_ type: String, jsonBody:[String:Any], completion: UsergridResponseCompletion? = nil) { + let request = UsergridRequest(method: .post, baseUrl: self.clientAppURL, paths: [type], auth: self.authForRequests(), - headers: UsergridRequest.JSON_CONTENT_TYPE_HEADER, - jsonBody: jsonBody) + headers: UsergridRequest.jsonHeaderContentType(), + jsonBody: jsonBody as Any?) self.sendRequest(request, completion: completion) } @@ -614,13 +614,13 @@ public class UsergridClient: NSObject, NSCoding { - parameter jsonBody: The valid JSON body dictionaries to use when creating the `UsergridEntity` objects. - parameter completion: The optional completion block that will be called once the request has completed. */ - public func POST(type: String, jsonBodies:[[String:AnyObject]], completion: UsergridResponseCompletion? = nil) { - let request = UsergridRequest(method: .Post, + public func POST(_ type: String, jsonBodies:[[String:Any]], completion: UsergridResponseCompletion? = nil) { + let request = UsergridRequest(method: .post, baseUrl: self.clientAppURL, paths: [type], auth: self.authForRequests(), - headers: UsergridRequest.JSON_CONTENT_TYPE_HEADER, - jsonBody: jsonBodies) + headers: UsergridRequest.jsonHeaderContentType(), + jsonBody: jsonBodies as Any?) self.sendRequest(request, completion: completion) } @@ -632,15 +632,15 @@ public class UsergridClient: NSObject, NSCoding { - parameter jsonBody: The valid JSON body dictionary to use when creating the `UsergridEntity`. - parameter completion: The optional completion block that will be called once the request has completed. */ - public func POST(type: String, name: String, jsonBody:[String:AnyObject], completion: UsergridResponseCompletion? = nil) { + public func POST(_ type: String, name: String, jsonBody:[String:Any], completion: UsergridResponseCompletion? = nil) { var jsonBodyWithName = jsonBody - jsonBodyWithName[UsergridEntityProperties.Name.stringValue] = name - let request = UsergridRequest(method: .Post, + jsonBodyWithName[UsergridEntityProperties.name.stringValue] = name + let request = UsergridRequest(method: .post, baseUrl: self.clientAppURL, paths: [type], auth: self.authForRequests(), - headers: UsergridRequest.JSON_CONTENT_TYPE_HEADER, - jsonBody: jsonBodyWithName) + headers: UsergridRequest.jsonHeaderContentType(), + jsonBody: jsonBodyWithName as Any?) self.sendRequest(request, completion: completion) } @@ -655,10 +655,10 @@ public class UsergridClient: NSObject, NSCoding { - parameter entity: The `UsergridEntity` to delete. - parameter completion: The optional completion block that will be called once the request has completed. */ - public func DELETE(entity:UsergridEntity, completion: UsergridResponseCompletion? = nil) { + public func DELETE(_ entity:UsergridEntity, completion: UsergridResponseCompletion? = nil) { guard let uuidOrName = entity.uuidOrName else { - completion?(response: UsergridResponse(client:self, errorName: "No UUID or name found.", errorDescription: "The entity object must have a `uuid` or `name` assigned.")) + completion?(UsergridResponse(client:self, errorName: "No UUID or name found.", errorDescription: "The entity object must have a `uuid` or `name` assigned.")) return } @@ -673,19 +673,19 @@ public class UsergridClient: NSObject, NSCoding { - parameter query: The query to use when filtering what entities to delete. - parameter queryCompletion: The optional completion block that will be called once the request has completed. */ - public func DELETE(query:UsergridQuery, queryCompletion: UsergridResponseCompletion? = nil) { + public func DELETE(_ query:UsergridQuery, queryCompletion: UsergridResponseCompletion? = nil) { guard let type = query.collectionName else { - queryCompletion?(response: UsergridResponse(client:self, errorName: "Query collection name invalid.", errorDescription: "Query is missing a collection name.")) + queryCompletion?(UsergridResponse(client:self, errorName: "Query collection name invalid.", errorDescription: "Query is missing a collection name.")) return } - let request = UsergridRequest(method: .Delete, + let request = UsergridRequest(method: .delete, baseUrl: self.clientAppURL, paths: [type], query: query, auth: self.authForRequests(), - headers: UsergridRequest.JSON_CONTENT_TYPE_HEADER) + headers: UsergridRequest.jsonHeaderContentType()) self.sendRequest(request, completion: queryCompletion) } @@ -696,12 +696,12 @@ public class UsergridClient: NSObject, NSCoding { - parameter uuidOrName: The UUID or name of the `UsergridEntity`. - parameter completion: The optional completion block that will be called once the request has completed. */ - public func DELETE(type:String, uuidOrName: String, completion: UsergridResponseCompletion? = nil) { - let request = UsergridRequest(method: .Delete, + public func DELETE(_ type:String, uuidOrName: String, completion: UsergridResponseCompletion? = nil) { + let request = UsergridRequest(method: .delete, baseUrl: self.clientAppURL, paths: [type,uuidOrName], auth: self.authForRequests(), - headers: UsergridRequest.JSON_CONTENT_TYPE_HEADER) + headers: UsergridRequest.jsonHeaderContentType()) self.sendRequest(request, completion: completion) } @@ -715,11 +715,11 @@ public class UsergridClient: NSObject, NSCoding { - parameter to: The `UsergridEntity` which is connected. - parameter completion: The optional completion block that will be called once the request has completed. */ - public func connect(entity:UsergridEntity, relationship:String, to:UsergridEntity, completion: UsergridResponseCompletion? = nil) { + public func connect(_ entity:UsergridEntity, relationship:String, to:UsergridEntity, completion: UsergridResponseCompletion? = nil) { guard let entityID = entity.uuidOrName, let toID = to.uuidOrName else { - completion?(response: UsergridResponse(client: self, errorName: "Invalid Entity Connection Attempt.", errorDescription: "One or both entities that are attempting to be connected do not contain a valid UUID or Name property.")) + completion?(UsergridResponse(client: self, errorName: "Invalid Entity Connection Attempt.", errorDescription: "One or both entities that are attempting to be connected do not contain a valid UUID or Name property.")) return } self.connect(entity.type, entityID: entityID, relationship: relationship, toType: to.type, toID: toID, completion: completion) @@ -735,7 +735,7 @@ public class UsergridClient: NSObject, NSCoding { - parameter toName: The name of the entity you are connecting to. - parameter completion: The optional completion block that will be called once the request has completed. */ - public func connect(entityType:String, entityID:String, relationship:String, toType:String, toName: String, completion: UsergridResponseCompletion? = nil) { + public func connect(_ entityType:String, entityID:String, relationship:String, toType:String, toName: String, completion: UsergridResponseCompletion? = nil) { self.connect(entityType, entityID: entityID, relationship: relationship, toType: toType, toID: toName, completion: completion) } @@ -749,14 +749,14 @@ public class UsergridClient: NSObject, NSCoding { - parameter toID: The UUID of the entity you are connecting to. - parameter completion: The optional completion block that will be called once the request has completed. */ - public func connect(entityType:String, entityID:String, relationship:String, toType:String?, toID: String, completion: UsergridResponseCompletion? = nil) { + public func connect(_ entityType:String, entityID:String, relationship:String, toType:String?, toID: String, completion: UsergridResponseCompletion? = nil) { var paths = [entityType,entityID,relationship] if let toType = toType { paths.append(toType) } paths.append(toID) - let request = UsergridRequest(method: .Post, + let request = UsergridRequest(method: .post, baseUrl: self.clientAppURL, paths: paths, auth: self.authForRequests()) @@ -771,11 +771,11 @@ public class UsergridClient: NSObject, NSCoding { - parameter from: The `UsergridEntity` which is connected. - parameter completion: The optional completion block that will be called once the request has completed. */ - public func disconnect(entity:UsergridEntity, relationship:String, from:UsergridEntity, completion: UsergridResponseCompletion? = nil) { + public func disconnect(_ entity:UsergridEntity, relationship:String, from:UsergridEntity, completion: UsergridResponseCompletion? = nil) { guard let entityID = entity.uuidOrName, let fromID = from.uuidOrName else { - completion?(response: UsergridResponse(client: self, errorName: "Invalid Entity Disconnect Attempt.", errorDescription: "The connecting and connected entities must have a `uuid` or `name` assigned.")) + completion?(UsergridResponse(client: self, errorName: "Invalid Entity Disconnect Attempt.", errorDescription: "The connecting and connected entities must have a `uuid` or `name` assigned.")) return } @@ -792,7 +792,7 @@ public class UsergridClient: NSObject, NSCoding { - parameter fromName: The name of the entity you are disconnecting from. - parameter completion: The optional completion block that will be called once the request has completed. */ - public func disconnect(entityType:String, entityID:String, relationship:String, fromType:String, fromName: String, completion: UsergridResponseCompletion? = nil) { + public func disconnect(_ entityType:String, entityID:String, relationship:String, fromType:String, fromName: String, completion: UsergridResponseCompletion? = nil) { self.disconnect(entityType, entityID: entityID, relationship: relationship, fromType: fromType, fromID: fromName, completion: completion) } @@ -806,7 +806,7 @@ public class UsergridClient: NSObject, NSCoding { - parameter toID: The UUID of the entity you are disconnecting from. - parameter completion: The optional completion block that will be called once the request has completed. */ - public func disconnect(entityType:String, entityID:String, relationship:String, fromType:String?, fromID: String, completion: UsergridResponseCompletion? = nil) { + public func disconnect(_ entityType:String, entityID:String, relationship:String, fromType:String?, fromID: String, completion: UsergridResponseCompletion? = nil) { var paths = [entityType,entityID,relationship] if let fromType = fromType { @@ -814,7 +814,7 @@ public class UsergridClient: NSObject, NSCoding { } paths.append(fromID) - let request = UsergridRequest(method: .Delete, + let request = UsergridRequest(method: .delete, baseUrl: self.clientAppURL, paths: paths, auth: self.authForRequests()) @@ -829,10 +829,10 @@ public class UsergridClient: NSObject, NSCoding { - parameter query: The optional query. - parameter completion: The optional completion block that will be called once the request has completed. */ - public func getConnections(direction:UsergridDirection, entity:UsergridEntity, relationship:String, query:UsergridQuery? = nil, completion:UsergridResponseCompletion? = nil) { + public func getConnections(_ direction:UsergridDirection, entity:UsergridEntity, relationship:String, query:UsergridQuery? = nil, completion:UsergridResponseCompletion? = nil) { guard let uuidOrName = entity.uuidOrName else { - completion?(response: UsergridResponse(client: self, errorName: "Invalid Entity Get Connections Attempt.", errorDescription: "The entity must have a `uuid` or `name` assigned.")) + completion?(UsergridResponse(client: self, errorName: "Invalid Entity Get Connections Attempt.", errorDescription: "The entity must have a `uuid` or `name` assigned.")) return } self.getConnections(direction, type: entity.type, uuidOrName: uuidOrName, relationship: relationship, query:query, completion: completion) @@ -848,8 +848,8 @@ public class UsergridClient: NSObject, NSCoding { - parameter query: The optional query. - parameter completion: The optional completion block that will be called once the request has completed. */ - public func getConnections(direction:UsergridDirection, type:String, uuidOrName:String, relationship:String, query:UsergridQuery? = nil, completion:UsergridResponseCompletion? = nil) { - let request = UsergridRequest(method: .Get, + public func getConnections(_ direction:UsergridDirection, type:String, uuidOrName:String, relationship:String, query:UsergridQuery? = nil, completion:UsergridResponseCompletion? = nil) { + let request = UsergridRequest(method: .get, baseUrl: self.clientAppURL, paths: [type, uuidOrName, direction.connectionValue, relationship], query: query, @@ -866,8 +866,8 @@ public class UsergridClient: NSObject, NSCoding { - parameter query: The optional query. - parameter completion: The optional completion block that will be called once the request has completed. */ - public func getConnections(direction:UsergridDirection, uuid:String, relationship:String, query:UsergridQuery? = nil, completion:UsergridResponseCompletion? = nil) { - let request = UsergridRequest(method: .Get, + public func getConnections(_ direction:UsergridDirection, uuid:String, relationship:String, query:UsergridQuery? = nil, completion:UsergridResponseCompletion? = nil) { + let request = UsergridRequest(method: .get, baseUrl: self.clientAppURL, paths: [uuid, direction.connectionValue, relationship], query: query, @@ -885,7 +885,7 @@ public class UsergridClient: NSObject, NSCoding { - parameter progress: The optional progress block that will be called to update the progress of the upload. - parameter completion: The optional completion block that will be called once the request has completed. */ - public func uploadAsset(entity:UsergridEntity, asset:UsergridAsset, progress:UsergridAssetRequestProgress? = nil, completion:UsergridAssetUploadCompletion? = nil) { + public func uploadAsset(_ entity:UsergridEntity, asset:UsergridAsset, progress:UsergridAssetRequestProgress? = nil, completion:UsergridAssetUploadCompletion? = nil) { let assetRequest = UsergridAssetUploadRequest(baseUrl: self.clientAppURL, paths: [entity.type,entity.uuidOrName!], auth: self.authForRequests(), @@ -898,7 +898,7 @@ public class UsergridClient: NSObject, NSCoding { entity.fileMetaData = responseEntityFileMetaData } } - completion?(asset: asset, response: response) + completion?(asset, response) } } @@ -910,14 +910,14 @@ public class UsergridClient: NSObject, NSCoding { - parameter progress: The optional progress block that will be called to update the progress of the download. - parameter completion: The optional completion block that will be called once the request has completed. */ - public func downloadAsset(entity:UsergridEntity, contentType:String, progress:UsergridAssetRequestProgress? = nil, completion:UsergridAssetDownloadCompletion? = nil) { + public func downloadAsset(_ entity:UsergridEntity, contentType:String, progress:UsergridAssetRequestProgress? = nil, completion:UsergridAssetDownloadCompletion? = nil) { guard entity.hasAsset else { - completion?(asset: nil, error: UsergridResponseError(errorName: "Download asset failed.", errorDescription: "Entity does not have an asset attached.")) + completion?(nil, UsergridResponseError(errorName: "Download asset failed.", errorDescription: "Entity does not have an asset attached.")) return } - let downloadAssetRequest = UsergridRequest(method: .Get, + let downloadAssetRequest = UsergridRequest(method: .get, baseUrl: self.clientAppURL, paths: [entity.type,entity.uuidOrName!], auth: self.authForRequests(), @@ -925,7 +925,7 @@ public class UsergridClient: NSObject, NSCoding { _requestManager.performAssetDownload(contentType, usergridRequest: downloadAssetRequest, progress: progress, completion: { (asset, error) -> Void in entity.asset = asset - completion?(asset: asset, error: error) + completion?(asset, error) }) } } http://git-wip-us.apache.org/repos/asf/usergrid-swift/blob/b022377f/Source/UsergridClientConfig.swift ---------------------------------------------------------------------- diff --git a/Source/UsergridClientConfig.swift b/Source/UsergridClientConfig.swift index 64ebd4f..9d1e057 100644 --- a/Source/UsergridClientConfig.swift +++ b/Source/UsergridClientConfig.swift @@ -45,7 +45,7 @@ public class UsergridClientConfig : NSObject, NSCoding { public var baseUrl: String = UsergridClient.DEFAULT_BASE_URL /// The `UsergridAuthMode` value used to determine what type of token will be sent, if any. - public var authMode: UsergridAuthMode = .User + public var authMode: UsergridAuthMode = .user /// Whether or not the `UsergridClient` current user will be saved and restored from the keychain. public var persistCurrentUserInKeychain: Bool = true @@ -115,9 +115,9 @@ public class UsergridClientConfig : NSObject, NSCoding { - returns: A decoded `UsergridUser` object. */ public required init?(coder aDecoder: NSCoder) { - guard let appId = aDecoder.decodeObjectForKey("appId") as? String, - let orgId = aDecoder.decodeObjectForKey("orgId") as? String, - let baseUrl = aDecoder.decodeObjectForKey("baseUrl") as? String + guard let appId = aDecoder.decodeObject(forKey: "appId") as? String, + let orgId = aDecoder.decodeObject(forKey: "orgId") as? String, + let baseUrl = aDecoder.decodeObject(forKey: "baseUrl") as? String else { self.appId = "" self.orgId = "" @@ -127,9 +127,9 @@ public class UsergridClientConfig : NSObject, NSCoding { self.appId = appId self.orgId = orgId self.baseUrl = baseUrl - self.appAuth = aDecoder.decodeObjectForKey("appAuth") as? UsergridAppAuth - self.persistCurrentUserInKeychain = aDecoder.decodeBoolForKey("persistCurrentUserInKeychain") ?? true - self.authMode = UsergridAuthMode(rawValue:aDecoder.decodeIntegerForKey("authMode")) ?? .None + self.appAuth = aDecoder.decodeObject(forKey: "appAuth") as? UsergridAppAuth + self.persistCurrentUserInKeychain = aDecoder.decodeBool(forKey: "persistCurrentUserInKeychain") + self.authMode = (UsergridAuthMode(rawValue:aDecoder.decodeInteger(forKey: "authMode")) ?? .none)! super.init() } @@ -138,12 +138,12 @@ public class UsergridClientConfig : NSObject, NSCoding { - parameter aCoder: The encoder. */ - public func encodeWithCoder(aCoder: NSCoder) { - aCoder.encodeObject(self.appId, forKey: "appId") - aCoder.encodeObject(self.orgId, forKey: "orgId") - aCoder.encodeObject(self.baseUrl, forKey: "baseUrl") - aCoder.encodeObject(self.appAuth, forKey: "appAuth") - aCoder.encodeBool(self.persistCurrentUserInKeychain, forKey: "persistCurrentUserInKeychain") - aCoder.encodeInteger(self.authMode.rawValue, forKey: "authMode") + public func encode(with aCoder: NSCoder) { + aCoder.encode(self.appId, forKey: "appId") + aCoder.encode(self.orgId, forKey: "orgId") + aCoder.encode(self.baseUrl, forKey: "baseUrl") + aCoder.encode(self.appAuth, forKey: "appAuth") + aCoder.encode(self.persistCurrentUserInKeychain, forKey: "persistCurrentUserInKeychain") + aCoder.encode(self.authMode.rawValue, forKey: "authMode") } } http://git-wip-us.apache.org/repos/asf/usergrid-swift/blob/b022377f/Source/UsergridDevice.swift ---------------------------------------------------------------------- diff --git a/Source/UsergridDevice.swift b/Source/UsergridDevice.swift index 004c42c..5eb3850 100644 --- a/Source/UsergridDevice.swift +++ b/Source/UsergridDevice.swift @@ -47,13 +47,13 @@ public class UsergridDevice : UsergridEntity { // MARK: - Instance Properties - /// Property helper method for the `UsergridDevice` objects device model. - public var model: String { return super[UsergridDeviceProperties.Model.stringValue] as! String } + public var model: String { return super[UsergridDeviceProperties.model.stringValue] as! String } /// Property helper method for the `UsergridDevice` objects device platform. - public var platform: String { return super[UsergridDeviceProperties.Platform.stringValue] as! String } + public var platform: String { return super[UsergridDeviceProperties.platform.stringValue] as! String } /// Property helper method for the `UsergridDevice` objects device operating system version. - public var osVersion: String { return super[UsergridDeviceProperties.OSVersion.stringValue] as! String } + public var osVersion: String { return super[UsergridDeviceProperties.osVersion.stringValue] as! String } /// The shared instance of `UsergridDevice`. public static var sharedDevice: UsergridDevice = UsergridDevice.getOrCreateSharedDeviceFromKeychain() @@ -80,7 +80,7 @@ public class UsergridDevice : UsergridEntity { - returns: A new `UsergridDevice` object. */ - required public init(type:String, name:String? = nil, propertyDict:[String:AnyObject]? = nil) { + required public init(type:String, name:String? = nil, propertyDict:[String:Any]? = nil) { super.init(type: type, name: name, propertyDict: propertyDict) } @@ -102,8 +102,8 @@ public class UsergridDevice : UsergridEntity { - parameter aCoder: The encoder. */ - public override func encodeWithCoder(aCoder: NSCoder) { - super.encodeWithCoder(aCoder) + public override func encode(with aCoder: NSCoder) { + super.encode(with: aCoder) } /** @@ -113,7 +113,7 @@ public class UsergridDevice : UsergridEntity { - parameter completion: An optional completion block that, if successful, will contain the updated/saved `UsergridEntity` object. */ - public override func save(completion: UsergridResponseCompletion? = nil) { + public override func save(_ completion: UsergridResponseCompletion? = nil) { self.save(Usergrid.sharedInstance, completion: completion) } @@ -126,14 +126,14 @@ public class UsergridDevice : UsergridEntity { - parameter client: The client to use when saving. - parameter completion: An optional completion block that, if successful, will contain the updated/saved `UsergridEntity` object. */ - public override func save(client: UsergridClient, completion: UsergridResponseCompletion? = nil) { + public override func save(_ client: UsergridClient, completion: UsergridResponseCompletion? = nil) { super.save(client) { (response) in if( response.ok ) { if( self == UsergridDevice.sharedDevice || self.isEqualToEntity(UsergridDevice.sharedDevice)) { UsergridDevice.saveSharedDeviceToKeychain() } } - completion?(response:response) + completion?(response) } } @@ -154,7 +154,7 @@ public class UsergridDevice : UsergridEntity { let uuid = usergridDevice["uuid"] ``` */ - override public subscript(propertyName: String) -> AnyObject? { + override public subscript(propertyName: String) -> Any? { get { return super[propertyName] } @@ -172,22 +172,22 @@ public class UsergridDevice : UsergridEntity { - returns: A property dictionary with the common properties set. */ - public static func commonDevicePropertyDict() -> [String:AnyObject] { - var commonDevicePropertyDict: [String:AnyObject] = [:] - commonDevicePropertyDict[UsergridEntityProperties.EntityType.stringValue] = UsergridDevice.DEVICE_ENTITY_TYPE + public static func commonDevicePropertyDict() -> [String:Any] { + var commonDevicePropertyDict: [String:Any] = [:] + commonDevicePropertyDict[UsergridEntityProperties.type.stringValue] = UsergridDevice.DEVICE_ENTITY_TYPE #if os(watchOS) - commonDevicePropertyDict[UsergridDeviceProperties.Model.stringValue] = WKInterfaceDevice.currentDevice().model - commonDevicePropertyDict[UsergridDeviceProperties.Platform.stringValue] = WKInterfaceDevice.currentDevice().systemName - commonDevicePropertyDict[UsergridDeviceProperties.OSVersion.stringValue] = WKInterfaceDevice.currentDevice().systemVersion + commonDevicePropertyDict[UsergridDeviceProperties.model.stringValue] = WKInterfaceDevice.current().model + commonDevicePropertyDict[UsergridDeviceProperties.platform.stringValue] = WKInterfaceDevice.current().systemName + commonDevicePropertyDict[UsergridDeviceProperties.osVersion.stringValue] = WKInterfaceDevice.current().systemVersion #elseif os(iOS) || os(tvOS) - commonDevicePropertyDict[UsergridDeviceProperties.Model.stringValue] = UIDevice.currentDevice().model - commonDevicePropertyDict[UsergridDeviceProperties.Platform.stringValue] = UIDevice.currentDevice().systemName - commonDevicePropertyDict[UsergridDeviceProperties.OSVersion.stringValue] = UIDevice.currentDevice().systemVersion + commonDevicePropertyDict[UsergridDeviceProperties.model.stringValue] = UIDevice.current.model + commonDevicePropertyDict[UsergridDeviceProperties.platform.stringValue] = UIDevice.current.systemName + commonDevicePropertyDict[UsergridDeviceProperties.osVersion.stringValue] = UIDevice.current.systemVersion #elseif os(OSX) - commonDevicePropertyDict[UsergridDeviceProperties.Model.stringValue] = "Mac" - commonDevicePropertyDict[UsergridDeviceProperties.Platform.stringValue] = "OSX" - commonDevicePropertyDict[UsergridDeviceProperties.OSVersion.stringValue] = NSProcessInfo.processInfo().operatingSystemVersionString + commonDevicePropertyDict[UsergridDeviceProperties.model.stringValue] = "Mac" + commonDevicePropertyDict[UsergridDeviceProperties.platform.stringValue] = "OSX" + commonDevicePropertyDict[UsergridDeviceProperties.osVersion.stringValue] = ProcessInfo.processInfo.operatingSystemVersionString #endif return commonDevicePropertyDict @@ -205,8 +205,8 @@ public class UsergridDevice : UsergridEntity { - parameter pushToken: The push token from Apple. - parameter notifierID: The notifier ID. */ - internal func applyPushToken(pushToken: NSData, notifierID: String) { - self[notifierID + USERGRID_NOTIFIER_ID_SUFFIX] = pushToken.description.stringByTrimmingCharactersInSet(NSCharacterSet(charactersInString: "<>")).stringByReplacingOccurrencesOfString(" ", withString: "") + internal func applyPushToken(_ pushToken: Data, notifierID: String) { + self[notifierID + USERGRID_NOTIFIER_ID_SUFFIX] = pushToken.description.trimmingCharacters(in: CharacterSet(charactersIn: "<>")).replacingOccurrences(of: " ", with: "") } }
