http://git-wip-us.apache.org/repos/asf/usergrid-swift/blob/b022377f/Source/UsergridEntity.swift
----------------------------------------------------------------------
diff --git a/Source/UsergridEntity.swift b/Source/UsergridEntity.swift
index dd169ed..7babee4 100644
--- a/Source/UsergridEntity.swift
+++ b/Source/UsergridEntity.swift
@@ -32,16 +32,16 @@ import CoreLocation
 
 `UsergridEntity` maintains a set of accessor properties for standard Usergrid 
schema properties (e.g. name, uuid), and supports helper methods for accessing 
any custom properties that might exist.
 */
-public class UsergridEntity: NSObject, NSCoding {
+open class UsergridEntity: NSObject, NSCoding {
 
     static private var subclassMappings: [String:UsergridEntity.Type] = 
[UsergridUser.USER_ENTITY_TYPE:UsergridUser.self,UsergridDevice.DEVICE_ENTITY_TYPE:UsergridDevice.self]
 
     // MARK: - Instance Properties -
 
     /// The property dictionary that stores the properties values of the 
`UsergridEntity` object.
-    private var properties: [String : AnyObject] {
+    private var properties: [String : Any] {
         didSet {
-            if let fileMetaData = 
properties.removeValueForKey(UsergridFileMetaData.FILE_METADATA) as? 
[String:AnyObject] {
+            if let fileMetaData = properties.removeValue(forKey: 
UsergridFileMetaData.FILE_METADATA) as? [String:Any] {
                 self.fileMetaData = UsergridFileMetaData(fileMetaDataJSON: 
fileMetaData)
             } else {
                 self.fileMetaData = nil
@@ -55,25 +55,25 @@ public class UsergridEntity: NSObject, NSCoding {
     /// The `UsergridFileMetaData` of this `UsergridEntity`.
     internal(set) public var fileMetaData : UsergridFileMetaData?
 
-    /// Property helper method for the `UsergridEntity` objects 
`UsergridEntityProperties.EntityType`.
-    public var type: String { return 
self.getEntitySpecificProperty(.EntityType) as! String }
+    /// Property helper method for the `UsergridEntity` objects 
`UsergridEntityProperties.type`.
+    public var type: String { return self.getEntitySpecificProperty(.type) as! 
String }
 
-    /// Property helper method for the `UsergridEntity` objects 
`UsergridEntityProperties.UUID`.
-    public var uuid: String? { return self.getEntitySpecificProperty(.UUID) 
as? String }
+    /// Property helper method for the `UsergridEntity` objects 
`UsergridEntityProperties.uuid`.
+    public var uuid: String? { return self.getEntitySpecificProperty(.uuid) 
as? String }
 
-    /// Property helper method for the `UsergridEntity` objects 
`UsergridEntityProperties.Name`.
-    public var name: String? { return self.getEntitySpecificProperty(.Name) 
as? String }
+    /// Property helper method for the `UsergridEntity` objects 
`UsergridEntityProperties.name`.
+    public var name: String? { return self.getEntitySpecificProperty(.name) 
as? String }
 
-    /// Property helper method for the `UsergridEntity` objects 
`UsergridEntityProperties.Created`.
-    public var created: NSDate? { return 
self.getEntitySpecificProperty(.Created) as? NSDate }
+    /// Property helper method for the `UsergridEntity` objects 
`UsergridEntityProperties.created`.
+    public var created: Date? { return 
self.getEntitySpecificProperty(.created) as? Date }
 
-    /// Property helper method for the `UsergridEntity` objects 
`UsergridEntityProperties.Modified`.
-    public var modified: NSDate? { return 
self.getEntitySpecificProperty(.Modified) as? NSDate }
+    /// Property helper method for the `UsergridEntity` objects 
`UsergridEntityProperties.modified`.
+    public var modified: Date? { return 
self.getEntitySpecificProperty(.modified) as? Date }
 
-    /// Property helper method for the `UsergridEntity` objects 
`UsergridEntityProperties.Location`.
+    /// Property helper method for the `UsergridEntity` objects 
`UsergridEntityProperties.location`.
     public var location: CLLocation? {
-        get { return self.getEntitySpecificProperty(.Location) as? CLLocation }
-        set(newLocation) { self[UsergridEntityProperties.Location.stringValue] 
= newLocation }
+        get { return self.getEntitySpecificProperty(.location) as? CLLocation }
+        set(newLocation) { self[UsergridEntityProperties.location.stringValue] 
= newLocation }
     }
 
     /// Property helper method to get the UUID or name of the `UsergridEntity`.
@@ -83,21 +83,21 @@ public class UsergridEntity: NSObject, NSCoding {
     public var isUser: Bool { return self is UsergridUser || self.type == 
UsergridUser.USER_ENTITY_TYPE }
 
     /// Tells you if there is an asset associated with this entity.
-    public var hasAsset: Bool { return self.asset != nil || 
self.fileMetaData?.contentLength > 0 }
+    public var hasAsset: Bool { return self.asset != nil || 
(self.fileMetaData?.contentLength ?? 0) > 0 }
 
     /// The JSON object value.
-    public var jsonObjectValue : [String:AnyObject] { return self.properties }
+    public var jsonObjectValue : [String:Any] { return self.properties }
 
     /// The string value.
-    public var stringValue : String { return NSString(data: try! 
NSJSONSerialization.dataWithJSONObject(self.jsonObjectValue, options: 
.PrettyPrinted), encoding: NSUTF8StringEncoding) as! String }
+    public var stringValue : String { return NSString(data: try! 
JSONSerialization.data(withJSONObject: self.jsonObjectValue, options: 
.prettyPrinted), encoding: String.Encoding.utf8.rawValue) as! String }
 
     /// The description.
-    public override var description : String {
+    open override var description : String {
         return "Properties of Entity: \(stringValue)."
     }
 
     /// The debug description.
-    public override var debugDescription : String {
+    open override var debugDescription : String {
         return "Properties of Entity: \(stringValue)."
     }
 
@@ -112,28 +112,28 @@ public class UsergridEntity: NSObject, NSCoding {
 
     - returns: A new `UsergridEntity` 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) {
         self.properties = propertyDict ?? [:]
         super.init()
 
         if self is UsergridUser {
-            self.properties[UsergridEntityProperties.EntityType.stringValue] = 
UsergridUser.USER_ENTITY_TYPE
+            self.properties[UsergridEntityProperties.type.stringValue] = 
UsergridUser.USER_ENTITY_TYPE
         } else if self is UsergridDevice {
-            self.properties[UsergridEntityProperties.EntityType.stringValue] = 
UsergridDevice.DEVICE_ENTITY_TYPE
+            self.properties[UsergridEntityProperties.type.stringValue] = 
UsergridDevice.DEVICE_ENTITY_TYPE
         } else {
-            self.properties[UsergridEntityProperties.EntityType.stringValue] = 
type
+            self.properties[UsergridEntityProperties.type.stringValue] = type
         }
 
         if let entityName = name {
-            self.properties[UsergridEntityProperties.Name.stringValue] = 
entityName
+            self.properties[UsergridEntityProperties.name.stringValue] = 
entityName
         }
 
-        if let fileMetaData = 
self.properties.removeValueForKey(UsergridFileMetaData.FILE_METADATA) as? 
[String:AnyObject] {
+        if let fileMetaData = self.properties.removeValue(forKey: 
UsergridFileMetaData.FILE_METADATA) as? [String:Any] {
             self.fileMetaData = UsergridFileMetaData(fileMetaDataJSON: 
fileMetaData)
         }
     }
 
-    internal func copyInternalsFromEntity(entity:UsergridEntity) {
+    internal func copyInternalsFromEntity(_ entity:UsergridEntity) {
         self.properties = entity.properties
     }
 
@@ -143,7 +143,7 @@ public class UsergridEntity: NSObject, NSCoding {
      - parameter type:       The type of the `Usergrid` object.
      - parameter toSubclass: The subclass `UsergridEntity.Type` to map it to.
      */
-    public static func 
mapCustomType(type:String,toSubclass:UsergridEntity.Type) {
+    public static func mapCustomType(_ 
type:String,toSubclass:UsergridEntity.Type) {
         UsergridEntity.subclassMappings[type] = toSubclass
     }
 
@@ -154,8 +154,8 @@ public class UsergridEntity: NSObject, NSCoding {
 
     - returns: A `UsergridEntity` object provided that the `type` key within 
the dictionay exists. Otherwise nil.
     */
-    public class func entity(jsonDict jsonDict: [String:AnyObject]) -> 
UsergridEntity? {
-        guard let type = 
jsonDict[UsergridEntityProperties.EntityType.stringValue] as? String
+    public class func entity(jsonDict: [String:Any]) -> UsergridEntity? {
+        guard let type = jsonDict[UsergridEntityProperties.type.stringValue] 
as? String
             else {
                 return nil
         }
@@ -171,7 +171,7 @@ public class UsergridEntity: NSObject, NSCoding {
 
     - returns: An array of `UsergridEntity`.
     */
-    public class func entities(jsonArray entitiesJSONArray: 
[[String:AnyObject]]) -> [UsergridEntity] {
+    public class func entities(jsonArray entitiesJSONArray: [[String:Any]]) -> 
[UsergridEntity] {
         var entityArray : [UsergridEntity] = []
         for entityJSONDict in entitiesJSONArray {
             if let entity = UsergridEntity.entity(jsonDict:entityJSONDict) {
@@ -191,15 +191,15 @@ public class UsergridEntity: NSObject, NSCoding {
     - returns: A decoded `UsergridUser` object.
     */
     required public init?(coder aDecoder: NSCoder) {
-        guard let properties = aDecoder.decodeObjectForKey("properties") as? 
[String:AnyObject]
+        guard let properties = aDecoder.decodeObject(forKey: "properties") as? 
[String:Any]
             else {
                 self.properties = [:]
                 super.init()
                 return nil
         }
         self.properties = properties
-        self.fileMetaData = aDecoder.decodeObjectForKey("fileMetaData") as? 
UsergridFileMetaData
-        self.asset = aDecoder.decodeObjectForKey("asset") as? UsergridAsset
+        self.fileMetaData = aDecoder.decodeObject(forKey: "fileMetaData") as? 
UsergridFileMetaData
+        self.asset = aDecoder.decodeObject(forKey: "asset") as? UsergridAsset
         super.init()
     }
 
@@ -208,10 +208,10 @@ public class UsergridEntity: NSObject, NSCoding {
 
      - parameter aCoder: The encoder.
      */
-    public func encodeWithCoder(aCoder: NSCoder) {
-        aCoder.encodeObject(self.properties, forKey: "properties")
-        aCoder.encodeObject(self.fileMetaData, forKey: "fileMetaData")
-        aCoder.encodeObject(self.asset, forKey: "asset")
+    open func encode(with aCoder: NSCoder) {
+        aCoder.encode(self.properties, forKey: "properties")
+        aCoder.encode(self.fileMetaData, forKey: "fileMetaData")
+        aCoder.encode(self.asset, forKey: "asset")
     }
 
     // MARK: - Property Manipulation -
@@ -225,13 +225,13 @@ public class UsergridEntity: NSObject, NSCoding {
         usergridEntity["propertyName"] = propertyValue
         ```
     */
-    public subscript(propertyName: String) -> AnyObject? {
+    public subscript(propertyName: String) -> Any? {
         get {
             if let entityProperty = 
UsergridEntityProperties.fromString(propertyName) {
                 return self.getEntitySpecificProperty(entityProperty)
             } else {
                 let propertyValue = self.properties[propertyName]
-                if propertyValue === NSNull() { // Let's just return nil for 
properties that have been removed instead of NSNull
+                if propertyValue is NSNull { // Let's just return nil for 
properties that have been removed instead of NSNull
                     return nil
                 } else {
                     return propertyValue
@@ -242,7 +242,7 @@ public class UsergridEntity: NSObject, NSCoding {
             if let value = propertyValue {
                 if let entityProperty = 
UsergridEntityProperties.fromString(propertyName) {
                     if entityProperty.isMutableForEntity(self) {
-                        if entityProperty == .Location {
+                        if entityProperty == .location {
                             if let location = value as? CLLocation {
                                 properties[propertyName] = 
[ENTITY_LATITUDE:location.coordinate.latitude,
                                                             
ENTITY_LONGITUDE:location.coordinate.longitude]
@@ -250,7 +250,7 @@ public class UsergridEntity: NSObject, NSCoding {
                                 properties[propertyName] = 
[ENTITY_LATITUDE:location.latitude,
                                                             
ENTITY_LONGITUDE:location.longitude]
                             } else if let location = value as? [String:Double] 
{
-                                if let lat = location[ENTITY_LATITUDE], long = 
location[ENTITY_LONGITUDE] {
+                                if let lat = location[ENTITY_LATITUDE], let 
long = location[ENTITY_LONGITUDE] {
                                     properties[propertyName] = 
[ENTITY_LATITUDE:lat,
                                                                 
ENTITY_LONGITUDE:long]
                                 }
@@ -282,7 +282,7 @@ public class UsergridEntity: NSObject, NSCoding {
     - parameter name:  The name of the property.
     - parameter value: The value to update to.
     */
-    public func putProperty(name:String,value:AnyObject?) {
+    public func putProperty(_ name:String,value:Any?) {
         self[name] = value
     }
 
@@ -291,7 +291,7 @@ public class UsergridEntity: NSObject, NSCoding {
 
     - parameter properties: The property dictionary containing the properties 
names and values.
     */
-    public func putProperties(properties:[String:AnyObject]) {
+    public func putProperties(_ properties:[String:Any]) {
         for (name,value) in properties {
             self.putProperty(name, value: value)
         }
@@ -302,7 +302,7 @@ public class UsergridEntity: NSObject, NSCoding {
 
     - parameter name: The name of the property.
     */
-    public func removeProperty(name:String) {
+    public func removeProperty(_ name:String) {
         self[name] = nil
     }
 
@@ -311,7 +311,7 @@ public class UsergridEntity: NSObject, NSCoding {
 
     - parameter propertyNames: An array of property names.
     */
-    public func removeProperties(propertyNames:[String]) {
+    public func removeProperties(_ propertyNames:[String]) {
         for name in propertyNames {
             self.removeProperty(name)
         }
@@ -323,8 +323,8 @@ public class UsergridEntity: NSObject, NSCoding {
     - parameter name:  The name of the property.
      - parameter value: The value or an array of values to append.
     */
-    public func append(name:String, value:AnyObject) {
-        self.insertArray(name, values:value as? [AnyObject] ?? [value], index: 
Int.max)
+    public func append(_ name:String, value:Any) {
+        self.insertArray(name, values:value as? [Any] ?? [value], index: 
Int.max)
     }
 
     /**
@@ -334,8 +334,8 @@ public class UsergridEntity: NSObject, NSCoding {
     - parameter index: The index to insert at.
     - parameter value: The value or an array of values to insert.
     */
-    public func insert(name:String, value:AnyObject, index:Int = 0) {
-        self.insertArray(name, values:value as? [AnyObject] ?? [value], index: 
index)
+    public func insert(_ name:String, value:Any, index:Int = 0) {
+        self.insertArray(name, values:value as? [Any] ?? [value], index: index)
     }
 
     /**
@@ -345,14 +345,14 @@ public class UsergridEntity: NSObject, NSCoding {
     - parameter index:  The index to insert at.
     - parameter values: The values to insert.
     */
-    private func insertArray(name:String,values:[AnyObject], index:Int = 0) {
+    private func insertArray(_ name:String,values:[Any], index:Int = 0) {
         if let propertyValue = self[name] {
-            if let arrayValue = propertyValue as? [AnyObject] {
+            if let arrayValue = propertyValue as? [Any] {
                 var arrayOfValues = arrayValue
                 if  index > arrayValue.count {
-                    arrayOfValues.appendContentsOf(values)
+                    arrayOfValues.append(contentsOf: values)
                 } else {
-                    arrayOfValues.insertContentsOf(values, at: index)
+                    arrayOfValues.insert(contentsOf: values, at: index)
                 }
                 self[name] = arrayOfValues
             } else {
@@ -372,8 +372,8 @@ public class UsergridEntity: NSObject, NSCoding {
 
     - parameter name: The name of the property.
     */
-    public func pop(name:String) {
-        if let arrayValue = self[name] as? [AnyObject] where arrayValue.count 
> 0 {
+    public func pop(_ name:String) {
+        if let arrayValue = self[name] as? [Any] , arrayValue.count > 0 {
             var arrayOfValues = arrayValue
             arrayOfValues.removeLast()
             self[name] = arrayOfValues
@@ -385,25 +385,25 @@ public class UsergridEntity: NSObject, NSCoding {
 
     - parameter name: The name of the property.
     */
-    public func shift(name:String) {
-        if let arrayValue = self[name] as? [AnyObject] where arrayValue.count 
> 0 {
+    public func shift(_ name:String) {
+        if let arrayValue = self[name] as? [Any] , arrayValue.count > 0 {
             var arrayOfValues = arrayValue
             arrayOfValues.removeFirst()
             self[name] = arrayOfValues
         }
     }
 
-    private func getEntitySpecificProperty(entityProperty: 
UsergridEntityProperties) -> AnyObject? {
-        var propertyValue: AnyObject? = nil
+    private func getEntitySpecificProperty(_ entityProperty: 
UsergridEntityProperties) -> Any? {
+        var propertyValue: Any? = nil
         switch entityProperty {
-            case .UUID,.EntityType,.Name :
+            case .uuid,.type,.name :
                 propertyValue = self.properties[entityProperty.stringValue]
-            case .Created,.Modified :
+            case .created,.modified :
                 if let milliseconds = 
self.properties[entityProperty.stringValue] as? Int {
-                    propertyValue = NSDate(milliseconds: 
milliseconds.description)
+                    propertyValue = Date(milliseconds: 
milliseconds.description)
                 }
-            case .Location :
-                if let locationDict = 
self.properties[entityProperty.stringValue] as? [String:Double], lat = 
locationDict[ENTITY_LATITUDE], long = locationDict[ENTITY_LONGITUDE] {
+            case .location :
+                if let locationDict = 
self.properties[entityProperty.stringValue] as? [String:Double], let lat = 
locationDict[ENTITY_LATITUDE], let long = locationDict[ENTITY_LONGITUDE] {
                     propertyValue = CLLocation(latitude: lat, longitude: long)
                 }
             }
@@ -417,7 +417,7 @@ public class UsergridEntity: NSObject, NSCoding {
 
     - parameter completion: An optional completion block that, if successful, 
will contain the reloaded `UsergridEntity` object.
     */
-    public func reload(completion: UsergridResponseCompletion? = nil) {
+    public func reload(_ completion: UsergridResponseCompletion? = nil) {
         self.reload(Usergrid.sharedInstance, completion: completion)
     }
 
@@ -427,10 +427,10 @@ public class UsergridEntity: NSObject, NSCoding {
     - parameter client:     The client to use when reloading.
     - parameter completion: An optional completion block that, if successful, 
will contain the reloaded `UsergridEntity` object.
     */
-    public func reload(client:UsergridClient, completion: 
UsergridResponseCompletion? = nil) {
+    public func reload(_ client:UsergridClient, completion: 
UsergridResponseCompletion? = nil) {
         guard let uuidOrName = self.uuidOrName
             else {
-                completion?(response: UsergridResponse(client: client, 
errorName: "Entity cannot be reloaded.", errorDescription: "Entity has neither 
an UUID or name specified."))
+                completion?(UsergridResponse(client: client, errorName: 
"Entity cannot be reloaded.", errorDescription: "Entity has neither an UUID or 
name specified."))
                 return
         }
 
@@ -438,7 +438,7 @@ public class UsergridEntity: NSObject, NSCoding {
             if let responseEntity = response.entity {
                 self.copyInternalsFromEntity(responseEntity)
             }
-            completion?(response: response)
+            completion?(response)
         }
     }
 
@@ -447,7 +447,7 @@ public class UsergridEntity: NSObject, NSCoding {
 
     - parameter completion: An optional completion block that, if successful, 
will contain the updated/saved `UsergridEntity` object.
     */
-    public func save(completion: UsergridResponseCompletion? = nil) {
+    public func save(_ completion: UsergridResponseCompletion? = nil) {
         self.save(Usergrid.sharedInstance, completion: completion)
     }
 
@@ -457,20 +457,20 @@ public class UsergridEntity: NSObject, NSCoding {
     - 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 func save(client:UsergridClient, completion: 
UsergridResponseCompletion? = nil) {
+    public func save(_ client:UsergridClient, completion: 
UsergridResponseCompletion? = nil) {
         if let _ = self.uuid { // If UUID exists we PUT otherwise POST
             client.PUT(self) { response in
                 if let responseEntity = response.entity {
                     self.copyInternalsFromEntity(responseEntity)
                 }
-                completion?(response: response)
+                completion?(response)
             }
         } else {
             client.POST(self) { response in
                 if let responseEntity = response.entity {
                     self.copyInternalsFromEntity(responseEntity)
                 }
-                completion?(response: response)
+                completion?(response)
             }
         }
     }
@@ -480,7 +480,7 @@ public class UsergridEntity: NSObject, NSCoding {
 
     - parameter completion: An optional completion block.
     */
-    public func remove(completion: UsergridResponseCompletion? = nil) {
+    public func remove(_ completion: UsergridResponseCompletion? = nil) {
         self.remove(Usergrid.sharedInstance, completion: completion)
     }
 
@@ -490,7 +490,7 @@ public class UsergridEntity: NSObject, NSCoding {
     - parameter client:     The client to use when removing.
     - parameter completion: An optional completion block.
     */
-    public func remove(client:UsergridClient, completion: 
UsergridResponseCompletion? = nil) {
+    public func remove(_ client:UsergridClient, completion: 
UsergridResponseCompletion? = nil) {
         client.DELETE(self, completion: completion)
     }
 
@@ -503,7 +503,7 @@ public class UsergridEntity: NSObject, NSCoding {
     - parameter progress:   An optional progress block to keep track of upload 
progress.
     - parameter completion: An optional completion block.
     */
-    public func uploadAsset(asset:UsergridAsset, 
progress:UsergridAssetRequestProgress? = nil, 
completion:UsergridAssetUploadCompletion? = nil) {
+    public func uploadAsset(_ asset:UsergridAsset, 
progress:UsergridAssetRequestProgress? = nil, 
completion:UsergridAssetUploadCompletion? = nil) {
         self.uploadAsset(Usergrid.sharedInstance, asset: asset, progress: 
progress, completion: completion)
     }
 
@@ -515,7 +515,7 @@ public class UsergridEntity: NSObject, NSCoding {
     - parameter progress:   An optional progress block to keep track of upload 
progress.
     - parameter completion: An optional completion block.
     */
-    public func uploadAsset(client:UsergridClient, asset:UsergridAsset, 
progress:UsergridAssetRequestProgress? = nil, 
completion:UsergridAssetUploadCompletion? = nil) {
+    public func uploadAsset(_ client:UsergridClient, asset:UsergridAsset, 
progress:UsergridAssetRequestProgress? = nil, 
completion:UsergridAssetUploadCompletion? = nil) {
         client.uploadAsset(self, asset: asset, progress:progress, 
completion:completion)
     }
 
@@ -526,7 +526,7 @@ public class UsergridEntity: NSObject, NSCoding {
     - parameter progress:    An optional progress block to keep track of 
download progress.
     - parameter completion:  An optional completion block.
     */
-    public func downloadAsset(contentType:String, 
progress:UsergridAssetRequestProgress? = nil, 
completion:UsergridAssetDownloadCompletion? = nil) {
+    public func downloadAsset(_ contentType:String, 
progress:UsergridAssetRequestProgress? = nil, 
completion:UsergridAssetDownloadCompletion? = nil) {
         self.downloadAsset(Usergrid.sharedInstance, contentType: contentType, 
progress: progress, completion: completion)
     }
 
@@ -538,7 +538,7 @@ public class UsergridEntity: NSObject, NSCoding {
     - parameter progress:    An optional progress block to keep track of 
download progress.
     - parameter completion:  An optional completion block.
     */
-    public func downloadAsset(client:UsergridClient, contentType:String, 
progress:UsergridAssetRequestProgress? = nil, 
completion:UsergridAssetDownloadCompletion? = nil) {
+    public func downloadAsset(_ client:UsergridClient, contentType:String, 
progress:UsergridAssetRequestProgress? = nil, 
completion:UsergridAssetDownloadCompletion? = nil) {
         client.downloadAsset(self, contentType: contentType, 
progress:progress, completion: completion)
     }
 
@@ -551,7 +551,7 @@ public class UsergridEntity: NSObject, NSCoding {
     - parameter toEntity:     The entity to connect.
     - parameter completion:   An optional completion block.
     */
-    public func connect(relationship:String, toEntity:UsergridEntity, 
completion: UsergridResponseCompletion? = nil) {
+    public func connect(_ relationship:String, toEntity:UsergridEntity, 
completion: UsergridResponseCompletion? = nil) {
         self.connect(Usergrid.sharedInstance, relationship: relationship, 
toEntity: toEntity, completion: completion)
     }
 
@@ -563,7 +563,7 @@ public class UsergridEntity: NSObject, NSCoding {
     - parameter toEntity:     The entity to connect.
     - parameter completion:   An optional completion block.
     */
-    public func connect(client:UsergridClient, relationship:String, 
toEntity:UsergridEntity, completion: UsergridResponseCompletion? = nil) {
+    public func connect(_ client:UsergridClient, relationship:String, 
toEntity:UsergridEntity, completion: UsergridResponseCompletion? = nil) {
         client.connect(self, relationship: relationship, to: toEntity, 
completion: completion)
     }
 
@@ -574,7 +574,7 @@ public class UsergridEntity: NSObject, NSCoding {
     - parameter fromEntity:   The entity to disconnect.
     - parameter completion:   An optional completion block.
     */
-    public func disconnect(relationship:String, fromEntity:UsergridEntity, 
completion: UsergridResponseCompletion? = nil) {
+    public func disconnect(_ relationship:String, fromEntity:UsergridEntity, 
completion: UsergridResponseCompletion? = nil) {
         self.disconnect(Usergrid.sharedInstance, relationship: relationship, 
fromEntity: fromEntity, completion: completion)
     }
 
@@ -586,7 +586,7 @@ public class UsergridEntity: NSObject, NSCoding {
     - parameter fromEntity:   The entity to disconnect.
     - parameter completion:   An optional completion block.
     */
-    public func disconnect(client:UsergridClient, relationship:String, 
fromEntity:UsergridEntity, completion: UsergridResponseCompletion? = nil) {
+    public func disconnect(_ client:UsergridClient, relationship:String, 
fromEntity:UsergridEntity, completion: UsergridResponseCompletion? = nil) {
         client.disconnect(self, relationship: relationship, from: fromEntity, 
completion: completion)
     }
 
@@ -598,7 +598,7 @@ public class UsergridEntity: NSObject, NSCoding {
     - parameter query:          The optional query.
     - parameter completion:     An optional completion block.
     */
-    public func getConnections(direction:UsergridDirection, 
relationship:String, query:UsergridQuery? = nil, 
completion:UsergridResponseCompletion? = nil) {
+    public func getConnections(_ direction:UsergridDirection, 
relationship:String, query:UsergridQuery? = nil, 
completion:UsergridResponseCompletion? = nil) {
         self.getConnections(Usergrid.sharedInstance, direction: direction, 
relationship: relationship, query: query, completion: completion)
     }
 
@@ -611,7 +611,7 @@ public class UsergridEntity: NSObject, NSCoding {
     - parameter query:        The optional query.
     - parameter completion:   An optional completion block.
     */
-    public func getConnections(client:UsergridClient, 
direction:UsergridDirection, relationship:String, query:UsergridQuery? = nil, 
completion:UsergridResponseCompletion? = nil) {
+    public func getConnections(_ client:UsergridClient, 
direction:UsergridDirection, relationship:String, query:UsergridQuery? = nil, 
completion:UsergridResponseCompletion? = nil) {
         client.getConnections(direction, entity: self, relationship: 
relationship, query:query, completion: completion)
     }
 
@@ -624,7 +624,7 @@ public class UsergridEntity: NSObject, NSCoding {
 
      - returns: If the two `UsergridEntity` objects are equal.  i.e. they have 
the same non nil uuidOrName.
      */
-    public func isEqualToEntity(entity: UsergridEntity?) -> Bool {
+    public func isEqualToEntity(_ entity: UsergridEntity?) -> Bool {
         guard let selfUUID = self.uuidOrName,
               let entityUUID = entity?.uuidOrName
             else {
@@ -632,4 +632,4 @@ public class UsergridEntity: NSObject, NSCoding {
         }
         return selfUUID == entityUUID
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/usergrid-swift/blob/b022377f/Source/UsergridEnums.swift
----------------------------------------------------------------------
diff --git a/Source/UsergridEnums.swift b/Source/UsergridEnums.swift
index fd0b625..2b32aa1 100644
--- a/Source/UsergridEnums.swift
+++ b/Source/UsergridEnums.swift
@@ -36,21 +36,21 @@ An enumeration that is used to determine what the 
`UsergridClient` will use for
     /**
     If the API call fails, the activity is treated as a failure with an 
appropriate HTTP status code.
     */
-    case None
+    case none
 
     /**
      If a non-expired `UsergridUserAuth` exists in 
`UsergridClient.currentUser`, this token is used to authenticate all API calls.
 
      If the API call fails, the activity is treated as a failure with an 
appropriate HTTP status code (This behavior is identical to authMode=.None).
      */
-    case User
+    case user
 
     /**
     If a non-expired `UsergridAppAuth` exists in `UsergridClient.appAuth`, 
this token is used to authenticate all API calls.
 
     If the API call fails, the activity is treated as a failure with an 
appropriate HTTP status code (This behavior is identical to authMode=.None).
     */
-    case App
+    case app
 }
 
 /**
@@ -61,17 +61,17 @@ An enumeration that is used to determine what the 
`UsergridClient` will use for
     // MARK: - Values -
 
     /// Corresponds to the property 'type'
-    case EntityType
+    case type
     /// Corresponds to the property 'uuid'
-    case UUID
+    case uuid
     /// Corresponds to the property 'name'
-    case Name
+    case name
     /// Corresponds to the property 'created'
-    case Created
+    case created
     /// Corresponds to the property 'modified'
-    case Modified
+    case modified
     /// Corresponds to the property 'location'
-    case Location
+    case location
 
     // MARK: - Methods -
 
@@ -82,14 +82,14 @@ An enumeration that is used to determine what the 
`UsergridClient` will use for
 
     - returns: The corresponding `UsergridEntityProperties` or nil.
     */
-    public static func fromString(stringValue: String) -> 
UsergridEntityProperties? {
-        switch stringValue.lowercaseString {
-            case ENTITY_TYPE: return .EntityType
-            case ENTITY_UUID: return .UUID
-            case ENTITY_NAME: return .Name
-            case ENTITY_CREATED: return .Created
-            case ENTITY_MODIFIED: return .Modified
-            case ENTITY_LOCATION: return .Location
+    public static func fromString(_ stringValue: String) -> 
UsergridEntityProperties? {
+        switch stringValue.lowercased() {
+            case ENTITY_TYPE: return .type
+            case ENTITY_UUID: return .uuid
+            case ENTITY_NAME: return .name
+            case ENTITY_CREATED: return .created
+            case ENTITY_MODIFIED: return .modified
+            case ENTITY_LOCATION: return .location
             default: return nil
         }
     }
@@ -97,12 +97,12 @@ An enumeration that is used to determine what the 
`UsergridClient` will use for
     /// Returns the string value.
     public var stringValue: String {
         switch self {
-            case .EntityType: return ENTITY_TYPE
-            case .UUID: return ENTITY_UUID
-            case .Name: return ENTITY_NAME
-            case .Created: return ENTITY_CREATED
-            case .Modified: return ENTITY_MODIFIED
-            case .Location: return ENTITY_LOCATION
+            case .type: return ENTITY_TYPE
+            case .uuid: return ENTITY_UUID
+            case .name: return ENTITY_NAME
+            case .created: return ENTITY_CREATED
+            case .modified: return ENTITY_MODIFIED
+            case .location: return ENTITY_LOCATION
         }
     }
 
@@ -113,11 +113,11 @@ An enumeration that is used to determine what the 
`UsergridClient` will use for
 
     - returns: If the `UsergridEntityProperties` is mutable for the given 
entity
     */
-    public func isMutableForEntity(entity:UsergridEntity) -> Bool {
+    public func isMutableForEntity(_ entity:UsergridEntity) -> Bool {
         switch self {
-            case .EntityType,.UUID,.Created,.Modified: return false
-            case .Location: return true
-            case .Name: return entity.isUser
+            case .type,.uuid,.created,.modified: return false
+            case .location: return true
+            case .name: return entity.isUser
         }
     }
 }
@@ -130,11 +130,11 @@ An enumeration that is used to determine what the 
`UsergridClient` will use for
     // MARK: - Values -
 
     /// Corresponds to the property 'deviceModel'
-    case Model
+    case model
     /// Corresponds to the property 'devicePlatform'
-    case Platform
+    case platform
     /// Corresponds to the property 'deviceOSVersion'
-    case OSVersion
+    case osVersion
 
     // MARK: - Methods -
 
@@ -145,11 +145,11 @@ An enumeration that is used to determine what the 
`UsergridClient` will use for
 
     - returns: The corresponding `UsergridDeviceProperties` or nil.
     */
-    public static func fromString(stringValue: String) -> 
UsergridDeviceProperties? {
-        switch stringValue.lowercaseString {
-            case DEVICE_MODEL: return .Model
-            case DEVICE_PLATFORM: return .Platform
-            case DEVICE_OSVERSION: return .OSVersion
+    public static func fromString(_ stringValue: String) -> 
UsergridDeviceProperties? {
+        switch stringValue.lowercased() {
+            case DEVICE_MODEL: return .model
+            case DEVICE_PLATFORM: return .platform
+            case DEVICE_OSVERSION: return .osVersion
             default: return nil
         }
     }
@@ -157,9 +157,9 @@ An enumeration that is used to determine what the 
`UsergridClient` will use for
     /// Returns the string value.
     public var stringValue: String {
         switch self {
-            case .Model: return DEVICE_MODEL
-            case .Platform: return DEVICE_PLATFORM
-            case .OSVersion: return DEVICE_OSVERSION
+            case .model: return DEVICE_MODEL
+            case .platform: return DEVICE_PLATFORM
+            case .osVersion: return DEVICE_OSVERSION
         }
     }
 }
@@ -172,21 +172,21 @@ An enumeration that is used to determine what the 
`UsergridClient` will use for
     // MARK: - Values -
 
     /// Corresponds to the property 'name'
-    case Name
+    case name
     /// Corresponds to the property 'username'
-    case Username
+    case username
     /// Corresponds to the property 'password'
-    case Password
+    case password
     /// Corresponds to the property 'email'
-    case Email
+    case email
     /// Corresponds to the property 'age'
-    case Age
+    case age
     /// Corresponds to the property 'activated'
-    case Activated
+    case activated
     /// Corresponds to the property 'disabled'
-    case Disabled
+    case disabled
     /// Corresponds to the property 'picture'
-    case Picture
+    case picture
 
     // MARK: - Methods -
 
@@ -197,16 +197,16 @@ An enumeration that is used to determine what the 
`UsergridClient` will use for
 
     - returns: The corresponding `UsergridUserProperties` or nil.
     */
-    public static func fromString(stringValue: String) -> 
UsergridUserProperties? {
-        switch stringValue.lowercaseString {
-            case ENTITY_NAME: return .Name
-            case USER_USERNAME: return .Username
-            case USER_PASSWORD: return .Password
-            case USER_EMAIL: return .Email
-            case USER_AGE: return .Age
-            case USER_ACTIVATED: return .Activated
-            case USER_DISABLED: return .Disabled
-            case USER_PICTURE: return .Picture
+    public static func fromString(_ stringValue: String) -> 
UsergridUserProperties? {
+        switch stringValue.lowercased() {
+            case ENTITY_NAME: return .name
+            case USER_USERNAME: return .username
+            case USER_PASSWORD: return .password
+            case USER_EMAIL: return .email
+            case USER_AGE: return .age
+            case USER_ACTIVATED: return .activated
+            case USER_DISABLED: return .disabled
+            case USER_PICTURE: return .picture
             default: return nil
         }
     }
@@ -214,14 +214,14 @@ An enumeration that is used to determine what the 
`UsergridClient` will use for
     /// Returns the string value.
     public var stringValue: String {
         switch self {
-            case .Name: return ENTITY_NAME
-            case .Username: return USER_USERNAME
-            case .Password: return USER_PASSWORD
-            case .Email: return USER_EMAIL
-            case .Age: return USER_AGE
-            case .Activated: return USER_ACTIVATED
-            case .Disabled: return USER_DISABLED
-            case .Picture: return USER_PICTURE
+            case .name: return ENTITY_NAME
+            case .username: return USER_USERNAME
+            case .password: return USER_PASSWORD
+            case .email: return USER_EMAIL
+            case .age: return USER_AGE
+            case .activated: return USER_ACTIVATED
+            case .disabled: return USER_DISABLED
+            case .picture: return USER_PICTURE
         }
     }
 }
@@ -234,15 +234,15 @@ An enumeration that is used to determine what the 
`UsergridClient` will use for
     // MARK: - Values -
 
     /// '='
-    case Equal
+    case equal
     /// '>'
-    case GreaterThan
+    case greaterThan
     /// '>='
-    case GreaterThanEqualTo
+    case greaterThanEqualTo
     /// '<'
-    case LessThan
+    case lessThan
     /// '<='
-    case LessThanEqualTo
+    case lessThanEqualTo
 
     // MARK: - Methods -
 
@@ -253,13 +253,13 @@ An enumeration that is used to determine what the 
`UsergridClient` will use for
 
     - returns: The corresponding `UsergridQueryOperator` or nil.
     */
-    public static func fromString(stringValue: String) -> 
UsergridQueryOperator? {
-        switch stringValue.lowercaseString {
-            case UsergridQuery.EQUAL: return .Equal
-            case UsergridQuery.GREATER_THAN: return .GreaterThan
-            case UsergridQuery.GREATER_THAN_EQUAL_TO: return 
.GreaterThanEqualTo
-            case UsergridQuery.LESS_THAN: return .LessThan
-            case UsergridQuery.LESS_THAN_EQUAL_TO: return .LessThanEqualTo
+    public static func fromString(_ stringValue: String) -> 
UsergridQueryOperator? {
+        switch stringValue.lowercased() {
+            case UsergridQuery.EQUAL: return .equal
+            case UsergridQuery.GREATER_THAN: return .greaterThan
+            case UsergridQuery.GREATER_THAN_EQUAL_TO: return 
.greaterThanEqualTo
+            case UsergridQuery.LESS_THAN: return .lessThan
+            case UsergridQuery.LESS_THAN_EQUAL_TO: return .lessThanEqualTo
             default: return nil
         }
     }
@@ -267,11 +267,11 @@ An enumeration that is used to determine what the 
`UsergridClient` will use for
     /// Returns the string value.
     public var stringValue: String {
         switch self {
-            case .Equal: return UsergridQuery.EQUAL
-            case .GreaterThan: return UsergridQuery.GREATER_THAN
-            case .GreaterThanEqualTo: return 
UsergridQuery.GREATER_THAN_EQUAL_TO
-            case .LessThan: return UsergridQuery.LESS_THAN
-            case .LessThanEqualTo: return UsergridQuery.LESS_THAN_EQUAL_TO
+            case .equal: return UsergridQuery.EQUAL
+            case .greaterThan: return UsergridQuery.GREATER_THAN
+            case .greaterThanEqualTo: return 
UsergridQuery.GREATER_THAN_EQUAL_TO
+            case .lessThan: return UsergridQuery.LESS_THAN
+            case .lessThanEqualTo: return UsergridQuery.LESS_THAN_EQUAL_TO
         }
     }
 }
@@ -284,9 +284,9 @@ An enumeration that is used to determine what the 
`UsergridClient` will use for
     // MARK: - Values -
 
     /// Sort order is ascending.
-    case Asc
+    case asc
     /// Sort order is descending.
-    case Desc
+    case desc
 
     // MARK: - Methods -
 
@@ -297,10 +297,10 @@ An enumeration that is used to determine what the 
`UsergridClient` will use for
 
     - returns: The corresponding `UsergridQuerySortOrder` or nil.
     */
-    public static func fromString(stringValue: String) -> 
UsergridQuerySortOrder? {
-        switch stringValue.lowercaseString {
-            case UsergridQuery.ASC: return .Asc
-            case UsergridQuery.DESC: return .Desc
+    public static func fromString(_ stringValue: String) -> 
UsergridQuerySortOrder? {
+        switch stringValue.lowercased() {
+            case UsergridQuery.ASC: return .asc
+            case UsergridQuery.DESC: return .desc
             default: return nil
         }
     }
@@ -308,8 +308,8 @@ An enumeration that is used to determine what the 
`UsergridClient` will use for
     /// Returns the string value.
     public var stringValue: String {
         switch self {
-            case .Asc: return UsergridQuery.ASC
-            case .Desc: return UsergridQuery.DESC
+            case .asc: return UsergridQuery.ASC
+            case .desc: return UsergridQuery.DESC
         }
     }
 }
@@ -322,17 +322,17 @@ An enumeration that is used to determine what the 
`UsergridClient` will use for
     // MARK: - Values -
 
     /// Content type: 'image/png'
-    case Png
+    case png
     /// Content type: 'image/jpeg'
-    case Jpeg
+    case jpeg
 
     // MARK: - Methods -
 
     /// Returns the string value.
     public var stringValue: String {
         switch self {
-            case .Png: return ASSET_IMAGE_PNG
-            case .Jpeg: return ASSET_IMAGE_JPEG
+            case .png: return ASSET_IMAGE_PNG
+            case .jpeg: return ASSET_IMAGE_JPEG
         }
     }
 }
@@ -345,18 +345,18 @@ An enumeration that is used to determine what the 
`UsergridClient` will use for
     // MARK: - Values -
 
     /// To get the entities that have created a connection to an entity. aka 
`connecting`
-    case In
+    case `in`
 
     /// To get the entities an entity has connected to. aka `connections`
-    case Out
+    case out
 
     // MARK: - Methods -
 
     /// Returns the connection value.
     public var connectionValue: String {
         switch self {
-            case .In: return CONNECTION_TYPE_IN
-            case .Out: return CONNECTION_TYPE_OUT
+            case .in: return CONNECTION_TYPE_IN
+            case .out: return CONNECTION_TYPE_OUT
         }
     }
 }
@@ -367,24 +367,24 @@ An enumeration that is used to determine what the 
`UsergridClient` will use for
 @objc public enum UsergridHttpMethod : Int {
 
     /// GET
-    case Get
+    case get
 
     /// PUT
-    case Put
+    case put
 
     /// POST
-    case Post
+    case post
 
     /// DELETE
-    case Delete
+    case delete
 
     /// Returns the string value.
     public var stringValue: String {
         switch self {
-            case .Get: return "GET"
-            case .Put: return "PUT"
-            case .Post: return "POST"
-            case .Delete: return "DELETE"
+            case .get: return "GET"
+            case .put: return "PUT"
+            case .post: return "POST"
+            case .delete: return "DELETE"
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/usergrid-swift/blob/b022377f/Source/UsergridExtensions.swift
----------------------------------------------------------------------
diff --git a/Source/UsergridExtensions.swift b/Source/UsergridExtensions.swift
index 30ff3a7..4370808 100644
--- a/Source/UsergridExtensions.swift
+++ b/Source/UsergridExtensions.swift
@@ -29,7 +29,7 @@ import Foundation
 private let kUsergrid_Milliseconds_Per_Second = 1000
 
 /// Extension methods to help create and manipulate `NSDate` objects returned 
by Usergrid.
-public extension NSDate {
+public extension Date {
     /**
      Creates a new `NSDate` object with the given milliseconds.
 
@@ -37,8 +37,8 @@ public extension NSDate {
 
      - returns: A new `NSDate` object.
      */
-    public convenience init(milliseconds: String) {
-        self.init(timeIntervalSince1970: (milliseconds as 
NSString).doubleValue / Double(kUsergrid_Milliseconds_Per_Second) )
+    public init(milliseconds: String) {
+        self.init(timeIntervalSince1970:(milliseconds as NSString).doubleValue 
/ Double(kUsergrid_Milliseconds_Per_Second))
     }
     /**
      Converts the `NSDate` object to milliseconds.
@@ -54,7 +54,7 @@ public extension NSDate {
      - returns: The number of milliseconds corresponding to the date as a 
string.
      */
     public func dateAsMillisecondsString() -> String {
-        return NSDate.stringFromMilleseconds(self.dateAsMilliseconds())
+        return Date.stringFromMilleseconds(self.dateAsMilliseconds())
     }
     /**
      Converts the number of milliseconds to a string.
@@ -63,8 +63,8 @@ public extension NSDate {
 
      - returns: The milliseconds as a string.
      */
-    public static func stringFromMilleseconds(milliseconds:Int) -> String {
-        return NSNumber(longLong: Int64(milliseconds)).stringValue
+    public static func stringFromMilleseconds(_ milliseconds:Int) -> String {
+        return NSNumber(value: Int64(milliseconds)).stringValue
     }
     /**
      Converts the `NSDate` object to the corresponding UNIX time stamp as a 
string.
@@ -72,7 +72,7 @@ public extension NSDate {
      - returns: The UNIX time stamp as a string.
      */
     public static func unixTimeStampString() -> String {
-        return NSDate.stringFromMilleseconds(NSDate.nowAsMilliseconds())
+        return Date.stringFromMilleseconds(Date.nowAsMilliseconds())
     }
     /**
      Converts the `NSDate` object to the corresponding UNIX time stamp.
@@ -80,7 +80,7 @@ public extension NSDate {
      - returns: The UNIX time stamp.
      */
     public static func unixTimeStamp() -> Int {
-        return NSDate.nowAsMilliseconds()
+        return Date.nowAsMilliseconds()
     }
     /**
      Converts the current date to milliseconds.
@@ -89,9 +89,9 @@ public extension NSDate {
      */
     public static func nowAsMilliseconds() -> Int {
         var tv = timeval()
-        let currentMillisecondTime = withUnsafeMutablePointer(&tv, { (t: 
UnsafeMutablePointer<timeval>) -> Int in
+        let currentMillisecondTime = withUnsafeMutablePointer(to: &tv, { (t: 
UnsafeMutablePointer<timeval>) -> Int in
             gettimeofday(t, nil)
-            return (Int(t.memory.tv_sec) * kUsergrid_Milliseconds_Per_Second) 
+ (Int(t.memory.tv_usec) / kUsergrid_Milliseconds_Per_Second)
+            return (Int(t.pointee.tv_sec) * kUsergrid_Milliseconds_Per_Second) 
+ (Int(t.pointee.tv_usec) / kUsergrid_Milliseconds_Per_Second)
         })
         return currentMillisecondTime
     }
@@ -99,12 +99,12 @@ public extension NSDate {
 
 internal extension String {
     func isUuid() -> Bool {
-        return (NSUUID(UUIDString: self) != nil) ? true : false
+        return (UUID(uuidString: self) != nil) ? true : false
     }
 }
 
 internal extension Dictionary {
-    mutating func update(other:Dictionary) {
+    mutating func update(_ other:Dictionary) {
         for (key,value) in other {
             self.updateValue(value, forKey:key)
         }

http://git-wip-us.apache.org/repos/asf/usergrid-swift/blob/b022377f/Source/UsergridFileMetaData.swift
----------------------------------------------------------------------
diff --git a/Source/UsergridFileMetaData.swift 
b/Source/UsergridFileMetaData.swift
index 4908430..b150e2e 100644
--- a/Source/UsergridFileMetaData.swift
+++ b/Source/UsergridFileMetaData.swift
@@ -51,7 +51,7 @@ public class UsergridFileMetaData : NSObject,NSCoding {
     public let lastModifiedTimeStamp: Int
 
     /// The `NSDate` object corresponding to the last modified time stamp.
-    public let lastModifiedDate: NSDate?
+    public let lastModifiedDate: Date?
 
     // MARK: - Initialization -
 
@@ -62,7 +62,7 @@ public class UsergridFileMetaData : NSObject,NSCoding {
 
     - returns: A new instance of `UsergridFileMetaData`.
     */
-    public init(fileMetaDataJSON:[String:AnyObject]) {
+    public init(fileMetaDataJSON:[String:Any]) {
         self.eTag = fileMetaDataJSON["etag"] as? String
         self.checkSum = fileMetaDataJSON["checksum"] as? String
         self.contentType = fileMetaDataJSON["content-type"] as? String
@@ -70,7 +70,7 @@ public class UsergridFileMetaData : NSObject,NSCoding {
         self.lastModifiedTimeStamp = fileMetaDataJSON["last-modified"] as? Int 
?? 0
 
         if self.lastModifiedTimeStamp > 0 {
-            self.lastModifiedDate = NSDate(milliseconds: 
self.lastModifiedTimeStamp.description)
+            self.lastModifiedDate = Date(milliseconds: 
self.lastModifiedTimeStamp.description)
         } else {
             self.lastModifiedDate = nil
         }
@@ -86,14 +86,14 @@ public class UsergridFileMetaData : NSObject,NSCoding {
     - returns: A decoded `UsergridUser` object.
     */
     required public init?(coder aDecoder: NSCoder) {
-        self.eTag = aDecoder.decodeObjectForKey("etag") as? String
-        self.checkSum = aDecoder.decodeObjectForKey("checksum") as? String
-        self.contentType = aDecoder.decodeObjectForKey("content-type") as? 
String
-        self.contentLength = aDecoder.decodeIntegerForKey("content-length") ?? 0
-        self.lastModifiedTimeStamp = 
aDecoder.decodeIntegerForKey("last-modified") ?? 0
+        self.eTag = aDecoder.decodeObject(forKey: "etag") as? String
+        self.checkSum = aDecoder.decodeObject(forKey: "checksum") as? String
+        self.contentType = aDecoder.decodeObject(forKey: "content-type") as? 
String
+        self.contentLength = aDecoder.decodeInteger(forKey: "content-length")
+        self.lastModifiedTimeStamp = aDecoder.decodeInteger(forKey: 
"last-modified")
 
         if self.lastModifiedTimeStamp > 0 {
-            self.lastModifiedDate = NSDate(milliseconds: 
self.lastModifiedTimeStamp.description)
+            self.lastModifiedDate = Date(milliseconds: 
self.lastModifiedTimeStamp.description)
         } else {
             self.lastModifiedDate = nil
         }
@@ -104,11 +104,11 @@ public class UsergridFileMetaData : NSObject,NSCoding {
 
      - parameter aCoder: The encoder.
      */
-    public func encodeWithCoder(aCoder: NSCoder) {
-        aCoder.encodeObject(self.eTag, forKey: "etag")
-        aCoder.encodeObject(self.checkSum, forKey: "checksum")
-        aCoder.encodeObject(self.contentType, forKey: "content-type")
-        aCoder.encodeInteger(self.contentLength, forKey: "content-length")
-        aCoder.encodeInteger(self.lastModifiedTimeStamp, forKey: 
"last-modified")
+    public func encode(with aCoder: NSCoder) {
+        aCoder.encode(self.eTag, forKey: "etag")
+        aCoder.encode(self.checkSum, forKey: "checksum")
+        aCoder.encode(self.contentType, forKey: "content-type")
+        aCoder.encode(self.contentLength, forKey: "content-length")
+        aCoder.encode(self.lastModifiedTimeStamp, forKey: "last-modified")
     }
 }

http://git-wip-us.apache.org/repos/asf/usergrid-swift/blob/b022377f/Source/UsergridKeychainHelpers.swift
----------------------------------------------------------------------
diff --git a/Source/UsergridKeychainHelpers.swift 
b/Source/UsergridKeychainHelpers.swift
index 4639832..b363a7f 100644
--- a/Source/UsergridKeychainHelpers.swift
+++ b/Source/UsergridKeychainHelpers.swift
@@ -34,8 +34,8 @@ private let USERGRID_KEYCHAIN_NAME = "Usergrid"
 private let USERGRID_DEVICE_KEYCHAIN_SERVICE = "SharedDevice"
 private let USERGRID_CURRENT_USER_KEYCHAIN_SERVICE = "CurrentUser"
 
-private func usergridGenericKeychainItem() -> [String:AnyObject] {
-    var keychainItem: [String:AnyObject] = [:]
+private func usergridGenericKeychainItem() -> [String:Any] {
+    var keychainItem: [String:Any] = [:]
     keychainItem[kSecClass as String] = kSecClassGenericPassword as String
     keychainItem[kSecAttrAccessible as String] = kSecAttrAccessibleAlways as 
String
     keychainItem[kSecAttrAccount as String] = USERGRID_KEYCHAIN_NAME
@@ -44,7 +44,7 @@ private func usergridGenericKeychainItem() -> 
[String:AnyObject] {
 
 internal extension UsergridDevice {
 
-    static func deviceKeychainItem() -> [String:AnyObject] {
+    static func deviceKeychainItem() -> [String:Any] {
         var keychainItem = usergridGenericKeychainItem()
         keychainItem[kSecAttrService as String] = 
USERGRID_DEVICE_KEYCHAIN_SERVICE
         return keychainItem
@@ -53,9 +53,9 @@ internal extension UsergridDevice {
     static func createNewDeviceKeychainUUID() -> String {
 
         #if os(watchOS) || os(OSX)
-            let usergridUUID = NSUUID().UUIDString
+            let usergridUUID = NSUUID().uuidString
         #elseif os(iOS) || os(tvOS)
-            let usergridUUID = 
UIDevice.currentDevice().identifierForVendor?.UUIDString ?? NSUUID().UUIDString
+            let usergridUUID = 
UIDevice.current.identifierForVendor?.uuidString ?? UUID().uuidString
         #endif
 
         return usergridUUID
@@ -63,21 +63,21 @@ internal extension UsergridDevice {
 
     private static func createNewSharedDevice() -> UsergridDevice {
         var deviceEntityDict = UsergridDevice.commonDevicePropertyDict()
-        deviceEntityDict[UsergridEntityProperties.UUID.stringValue] = 
UsergridDevice.createNewDeviceKeychainUUID()
+        deviceEntityDict[UsergridEntityProperties.uuid.stringValue] = 
UsergridDevice.createNewDeviceKeychainUUID()
         let sharedDevice = UsergridDevice(type: 
UsergridDevice.DEVICE_ENTITY_TYPE, name: nil, propertyDict: deviceEntityDict)
         return sharedDevice
     }
 
     static func getOrCreateSharedDeviceFromKeychain() -> UsergridDevice {
         var queryAttributes = UsergridDevice.deviceKeychainItem()
-        queryAttributes[kSecReturnData as String] = kCFBooleanTrue as Bool
-        queryAttributes[kSecReturnAttributes as String] = kCFBooleanTrue as 
Bool
+        queryAttributes[kSecReturnData as String] = (kCFBooleanTrue != nil) as 
Bool
+        queryAttributes[kSecReturnAttributes as String] = (kCFBooleanTrue != 
nil) as Bool
         var result: AnyObject?
-        let status = withUnsafeMutablePointer(&result) { 
SecItemCopyMatching(queryAttributes, UnsafeMutablePointer($0)) }
+        let status = withUnsafeMutablePointer(to: &result) { 
SecItemCopyMatching(queryAttributes as CFDictionary, UnsafeMutablePointer($0)) }
         if status == errSecSuccess {
             if let resultDictionary = result as? NSDictionary {
-                if let resultData = resultDictionary[kSecValueData as String] 
as? NSData {
-                    if let sharedDevice = 
NSKeyedUnarchiver.unarchiveObjectWithData(resultData) as? UsergridDevice {
+                if let resultData = resultDictionary[kSecValueData as String] 
as? Data {
+                    if let sharedDevice = 
NSKeyedUnarchiver.unarchiveObject(with: resultData) as? UsergridDevice {
                         return sharedDevice
                     } else {
                         UsergridDevice.deleteSharedDeviceKeychainItem()
@@ -92,17 +92,17 @@ internal extension UsergridDevice {
     }
 
 
-    static func saveSharedDeviceKeychainItem(device:UsergridDevice) {
+    static func saveSharedDeviceKeychainItem(_ device:UsergridDevice) {
         var queryAttributes = UsergridDevice.deviceKeychainItem()
-        queryAttributes[kSecReturnData as String] = kCFBooleanTrue as Bool
-        queryAttributes[kSecReturnAttributes as String] = kCFBooleanTrue as 
Bool
+        queryAttributes[kSecReturnData as String] = (kCFBooleanTrue != nil) as 
Bool
+        queryAttributes[kSecReturnAttributes as String] = (kCFBooleanTrue != 
nil) as Bool
 
-        let sharedDeviceData = 
NSKeyedArchiver.archivedDataWithRootObject(device);
+        let sharedDeviceData = NSKeyedArchiver.archivedData(withRootObject: 
device);
 
-        if SecItemCopyMatching(queryAttributes,nil) == errSecSuccess // Do we 
need to update keychain item or add a new one.
+        if SecItemCopyMatching(queryAttributes as CFDictionary,nil) == 
errSecSuccess // Do we need to update keychain item or add a new one.
         {
             let attributesToUpdate = [kSecValueData as String:sharedDeviceData]
-            let updateStatus = 
SecItemUpdate(UsergridDevice.deviceKeychainItem(), attributesToUpdate)
+            let updateStatus = 
SecItemUpdate(UsergridDevice.deviceKeychainItem() as CFDictionary, 
attributesToUpdate as CFDictionary)
             if updateStatus != errSecSuccess {
                 print("Error updating shared device data to keychain!")
             }
@@ -111,7 +111,7 @@ internal extension UsergridDevice {
         {
             var keychainItem = UsergridDevice.deviceKeychainItem()
             keychainItem[kSecValueData as String] = sharedDeviceData
-            let status = SecItemAdd(keychainItem, nil)
+            let status = SecItemAdd(keychainItem as CFDictionary, nil)
             if status != errSecSuccess {
                 print("Error adding shared device data to keychain!")
             }
@@ -120,10 +120,10 @@ internal extension UsergridDevice {
 
     static func deleteSharedDeviceKeychainItem() {
         var queryAttributes = UsergridDevice.deviceKeychainItem()
-        queryAttributes[kSecReturnData as String] = kCFBooleanFalse as Bool
-        queryAttributes[kSecReturnAttributes as String] = kCFBooleanFalse as 
Bool
-        if SecItemCopyMatching(queryAttributes,nil) == errSecSuccess {
-            let deleteStatus = SecItemDelete(queryAttributes)
+        queryAttributes[kSecReturnData as String] = (kCFBooleanFalse != nil) 
as Bool
+        queryAttributes[kSecReturnAttributes as String] = (kCFBooleanFalse != 
nil) as Bool
+        if SecItemCopyMatching(queryAttributes as CFDictionary,nil) == 
errSecSuccess {
+            let deleteStatus = SecItemDelete(queryAttributes as CFDictionary)
             if deleteStatus != errSecSuccess {
                 print("Error deleting shared device data to keychain!")
             }
@@ -133,23 +133,23 @@ internal extension UsergridDevice {
 
 internal extension UsergridUser {
 
-    static func userKeychainItem(client:UsergridClient) -> [String:AnyObject] {
+    static func userKeychainItem(_ client:UsergridClient) -> [String:Any] {
         var keychainItem = usergridGenericKeychainItem()
         keychainItem[kSecAttrService as String] = 
USERGRID_CURRENT_USER_KEYCHAIN_SERVICE + "." + client.appId + "." + client.orgId
         return keychainItem
     }
 
-    static func getCurrentUserFromKeychain(client:UsergridClient) -> 
UsergridUser? {
+    static func getCurrentUserFromKeychain(_ client:UsergridClient) -> 
UsergridUser? {
         var queryAttributes = UsergridUser.userKeychainItem(client)
-        queryAttributes[kSecReturnData as String] = kCFBooleanTrue as Bool
-        queryAttributes[kSecReturnAttributes as String] = kCFBooleanTrue as 
Bool
+        queryAttributes[kSecReturnData as String] = (kCFBooleanTrue != nil) as 
Bool
+        queryAttributes[kSecReturnAttributes as String] = (kCFBooleanTrue != 
nil) as Bool
 
         var result: AnyObject?
-        let status = withUnsafeMutablePointer(&result) { 
SecItemCopyMatching(queryAttributes, UnsafeMutablePointer($0)) }
+        let status = withUnsafeMutablePointer(to: &result) { 
SecItemCopyMatching(queryAttributes as CFDictionary, UnsafeMutablePointer($0)) }
         if status == errSecSuccess {
             if let resultDictionary = result as? NSDictionary {
-                if let resultData = resultDictionary[kSecValueData as String] 
as? NSData {
-                    if let currentUser = 
NSKeyedUnarchiver.unarchiveObjectWithData(resultData) as? UsergridUser {
+                if let resultData = resultDictionary[kSecValueData as String] 
as? Data {
+                    if let currentUser = 
NSKeyedUnarchiver.unarchiveObject(with: resultData) as? UsergridUser {
                         return currentUser
                     }
                 }
@@ -158,15 +158,15 @@ internal extension UsergridUser {
         return nil
     }
 
-    static func saveCurrentUserKeychainItem(client:UsergridClient, 
currentUser:UsergridUser) {
+    static func saveCurrentUserKeychainItem(_ client:UsergridClient, 
currentUser:UsergridUser) {
         var queryAttributes = UsergridUser.userKeychainItem(client)
-        queryAttributes[kSecReturnData as String] = kCFBooleanTrue as Bool
-        queryAttributes[kSecReturnAttributes as String] = kCFBooleanTrue as 
Bool
+        queryAttributes[kSecReturnData as String] = (kCFBooleanTrue != nil) as 
Bool
+        queryAttributes[kSecReturnAttributes as String] = (kCFBooleanTrue != 
nil) as Bool
 
-        if SecItemCopyMatching(queryAttributes,nil) == errSecSuccess // Do we 
need to update keychain item or add a new one.
+        if SecItemCopyMatching(queryAttributes as CFDictionary,nil) == 
errSecSuccess // Do we need to update keychain item or add a new one.
         {
-            let attributesToUpdate = [kSecValueData as 
String:NSKeyedArchiver.archivedDataWithRootObject(currentUser)]
-            let updateStatus = 
SecItemUpdate(UsergridUser.userKeychainItem(client), attributesToUpdate)
+            let attributesToUpdate = [kSecValueData as 
String:NSKeyedArchiver.archivedData(withRootObject: currentUser)]
+            let updateStatus = 
SecItemUpdate(UsergridUser.userKeychainItem(client) as CFDictionary, 
attributesToUpdate as CFDictionary)
             if updateStatus != errSecSuccess {
                 print("Error updating current user data to keychain!")
             }
@@ -174,20 +174,20 @@ internal extension UsergridUser {
         else
         {
             var keychainItem = UsergridUser.userKeychainItem(client)
-            keychainItem[kSecValueData as String] = 
NSKeyedArchiver.archivedDataWithRootObject(currentUser)
-            let status = SecItemAdd(keychainItem, nil)
+            keychainItem[kSecValueData as String] = 
NSKeyedArchiver.archivedData(withRootObject: currentUser)
+            let status = SecItemAdd(keychainItem as CFDictionary, nil)
             if status != errSecSuccess {
                 print("Error adding current user data to keychain!")
             }
         }
     }
 
-    static func deleteCurrentUserKeychainItem(client:UsergridClient) {
+    static func deleteCurrentUserKeychainItem(_ client:UsergridClient) {
         var queryAttributes = UsergridUser.userKeychainItem(client)
-        queryAttributes[kSecReturnData as String] = kCFBooleanFalse as Bool
-        queryAttributes[kSecReturnAttributes as String] = kCFBooleanFalse as 
Bool
-        if SecItemCopyMatching(queryAttributes,nil) == errSecSuccess {
-            let deleteStatus = SecItemDelete(queryAttributes)
+        queryAttributes[kSecReturnData as String] = (kCFBooleanFalse != nil) 
as Bool
+        queryAttributes[kSecReturnAttributes as String] = (kCFBooleanFalse != 
nil) as Bool
+        if SecItemCopyMatching(queryAttributes as CFDictionary,nil) == 
errSecSuccess {
+            let deleteStatus = SecItemDelete(queryAttributes as CFDictionary)
             if deleteStatus != errSecSuccess {
                 print("Error deleting current user data to keychain!")
             }

http://git-wip-us.apache.org/repos/asf/usergrid-swift/blob/b022377f/Source/UsergridQuery.swift
----------------------------------------------------------------------
diff --git a/Source/UsergridQuery.swift b/Source/UsergridQuery.swift
index c2a7000..a5c05bd 100644
--- a/Source/UsergridQuery.swift
+++ b/Source/UsergridQuery.swift
@@ -55,7 +55,7 @@ public class UsergridQuery : NSObject,NSCopying {
     
     - returns: Returns a new instance that’s a copy of the receiver.
     */
-    public func copyWithZone(zone: NSZone) -> AnyObject {
+    public func copy(with zone: NSZone?) -> Any {
         let queryCopy = UsergridQuery(self.collectionName)
         queryCopy.requirementStrings = NSArray(array:self.requirementStrings, 
copyItems: true) as! [String]
         queryCopy.urlTerms = NSArray(array:self.urlTerms, copyItems: true) as! 
[String]
@@ -76,7 +76,7 @@ public class UsergridQuery : NSObject,NSCopying {
     
     - returns: The constructed URL query sting.
     */
-    public func build(autoURLEncode: Bool = true) -> String {
+    public func build(_ autoURLEncode: Bool = true) -> String {
         return self.constructURLAppend(autoURLEncode)
     }
     
@@ -90,7 +90,8 @@ public class UsergridQuery : NSObject,NSCopying {
 
     - returns: `Self`
     */
-    public func contains(term: String, value: String) -> Self { return 
self.containsWord(term, value: value) }
+    @discardableResult
+    public func contains(_ term: String, value: String) -> Self { return 
self.containsWord(term, value: value) }
 
 
     /**
@@ -101,7 +102,8 @@ public class UsergridQuery : NSObject,NSCopying {
     
     - returns: `Self`
     */
-    public func containsString(term: String, value: String) -> Self { return 
self.containsWord(term, value: value) }
+    @discardableResult
+    public func containsString(_ term: String, value: String) -> Self { return 
self.containsWord(term, value: value) }
     
     /**
      Contains. Query: where term contains 'val%'.
@@ -111,7 +113,14 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
-    public func containsWord(term: String, value: String) -> Self { return 
self.addRequirement(term + UsergridQuery.SPACE + UsergridQuery.CONTAINS + 
UsergridQuery.SPACE + ((value.isUuid()) ? UsergridQuery.EMPTY_STRING : 
UsergridQuery.APOSTROPHE) + value + ((value.isUuid()) ? 
UsergridQuery.EMPTY_STRING : UsergridQuery.APOSTROPHE)) }
+    @discardableResult
+    public func containsWord(_ term: String, value: String) -> Self {
+        var operationValue: String = value
+        if !value.isUuid() {
+            operationValue = UsergridQuery.APOSTROPHE + value + 
UsergridQuery.APOSTROPHE
+        }
+        return self.addRequirement(term + UsergridQuery.SPACE + 
UsergridQuery.CONTAINS + UsergridQuery.SPACE + operationValue)
+    }
     
     /**
      Sort ascending. Query:. order by term asc.
@@ -120,7 +129,8 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
-    public func ascending(term: String) -> Self { return self.asc(term) }
+    @discardableResult
+    public func ascending(_ term: String) -> Self { return self.asc(term) }
     
     /**
      Sort ascending. Query:. order by term asc.
@@ -129,7 +139,8 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
-    public func asc(term: String) -> Self { return self.sort(term, sortOrder: 
.Asc) }
+    @discardableResult
+    public func asc(_ term: String) -> Self { return self.sort(term, 
sortOrder: .asc) }
     
     /**
      Sort descending. Query: order by term desc
@@ -138,7 +149,8 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
-    public func descending(term: String) -> Self { return self.desc(term) }
+    @discardableResult
+    public func descending(_ term: String) -> Self { return self.desc(term) }
     
     /**
      Sort descending. Query: order by term desc
@@ -147,7 +159,8 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
-    public func desc(term: String) -> Self { return self.sort(term, sortOrder: 
.Desc) }
+    @discardableResult
+    public func desc(_ term: String) -> Self { return self.sort(term, 
sortOrder: .desc) }
     
     /**
      Filter (or Equal-to). Query: where term = 'value'.
@@ -157,7 +170,8 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
-    public func filter(term: String, value: AnyObject) -> Self { return 
self.eq(term, value: value) }
+    @discardableResult
+    public func filter(_ term: String, value: Any) -> Self { return 
self.eq(term, value: value) }
     
     /**
      Equal-to. Query: where term = 'value'.
@@ -167,7 +181,8 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
-    public func equals(term: String, value: AnyObject) -> Self { return 
self.eq(term, value: value) }
+    @discardableResult
+    public func equals(_ term: String, value: Any) -> Self { return 
self.eq(term, value: value) }
     
     /**
      Equal-to. Query: where term = 'value'.
@@ -177,7 +192,8 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
-    public func eq(term: String, value: AnyObject) -> Self { return 
self.addOperationRequirement(term, operation:.Equal, value: value) }
+    @discardableResult
+    public func eq(_ term: String, value: Any) -> Self { return 
self.addOperationRequirement(term, operation:.equal, value: value) }
     
     /**
      Greater-than. Query: where term > 'value'.
@@ -187,7 +203,8 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
-    public func greaterThan(term: String, value: AnyObject) -> Self { return 
self.gt(term, value: value) }
+    @discardableResult
+    public func greaterThan(_ term: String, value: Any) -> Self { return 
self.gt(term, value: value) }
     
     /**
      Greater-than. Query: where term > 'value'.
@@ -197,7 +214,8 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
-    public func gt(term: String, value: AnyObject) -> Self { return 
self.addOperationRequirement(term, operation:.GreaterThan, value: value) }
+    @discardableResult
+    public func gt(_ term: String, value: Any) -> Self { return 
self.addOperationRequirement(term, operation:.greaterThan, value: value) }
     
     /**
      Greater-than-or-equal-to. Query: where term >= 'value'.
@@ -207,7 +225,8 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
-    public func greaterThanOrEqual(term: String, value: AnyObject) -> Self { 
return self.gte(term, value: value) }
+    @discardableResult
+    public func greaterThanOrEqual(_ term: String, value: Any) -> Self { 
return self.gte(term, value: value) }
     
     /**
      Greater-than-or-equal-to. Query: where term >= 'value'.
@@ -217,7 +236,8 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
-    public func gte(term: String, value: AnyObject) -> Self { return 
self.addOperationRequirement(term, operation:.GreaterThanEqualTo, value: value) 
}
+    @discardableResult
+    public func gte(_ term: String, value: Any) -> Self { return 
self.addOperationRequirement(term, operation:.greaterThanEqualTo, value: value) 
}
     
     /**
      Less-than. Query: where term < 'value'.
@@ -227,7 +247,8 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
-    public func lessThan(term: String, value: AnyObject) -> Self { return 
self.lt(term, value: value) }
+    @discardableResult
+    public func lessThan(_ term: String, value: Any) -> Self { return 
self.lt(term, value: value) }
     
     /**
      Less-than. Query: where term < 'value'.
@@ -237,7 +258,8 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
-    public func lt(term: String, value: AnyObject) -> Self { return 
self.addOperationRequirement(term, operation:.LessThan, value: value) }
+    @discardableResult
+    public func lt(_ term: String, value: Any) -> Self { return 
self.addOperationRequirement(term, operation:.lessThan, value: value) }
     
     /**
      Less-than-or-equal-to. Query: where term <= 'value'.
@@ -247,7 +269,8 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
-    public func lessThanOrEqual(term: String, value: AnyObject) -> Self { 
return self.lte(term, value: value) }
+    @discardableResult
+    public func lessThanOrEqual(_ term: String, value: Any) -> Self { return 
self.lte(term, value: value) }
     
     /**
      Less-than-or-equal-to. Query: where term <= 'value'.
@@ -257,7 +280,8 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
-    public func lte(term: String, value: AnyObject) -> Self { return 
self.addOperationRequirement(term, operation:.LessThanEqualTo, value: value) }
+    @discardableResult
+    public func lte(_ term: String, value: Any) -> Self { return 
self.addOperationRequirement(term, operation:.lessThanEqualTo, value: value) }
     
     /**
      Contains. Query: location within val of lat, long.
@@ -268,7 +292,8 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
-    public func locationWithin(distance: Float, latitude: Float, longitude: 
Float) -> Self {
+    @discardableResult
+    public func locationWithin(_ distance: Float, latitude: Float, longitude: 
Float) -> Self {
         return self.addRequirement(UsergridQuery.LOCATION + 
UsergridQuery.SPACE + UsergridQuery.WITHIN + UsergridQuery.SPACE + 
distance.description + UsergridQuery.SPACE + UsergridQuery.OF + 
UsergridQuery.SPACE + latitude.description + UsergridQuery.COMMA + 
longitude.description )
     }
     
@@ -277,10 +302,11 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
+    @discardableResult
     public func or() -> Self {
         if !self.requirementStrings.first!.isEmpty {
-            self.requirementStrings.insert(UsergridQuery.OR, atIndex: 0)
-            self.requirementStrings.insert(UsergridQuery.EMPTY_STRING, 
atIndex: 0)
+            self.requirementStrings.insert(UsergridQuery.OR, at: 0)
+            self.requirementStrings.insert(UsergridQuery.EMPTY_STRING, at: 0)
         }
         return self
     }
@@ -290,10 +316,11 @@ public class UsergridQuery : NSObject,NSCopying {
 
      - returns: `Self`
      */
+    @discardableResult
     public func and() -> Self {
         if !self.requirementStrings.first!.isEmpty {
-            self.requirementStrings.insert(UsergridQuery.AND, atIndex: 0)
-            self.requirementStrings.insert(UsergridQuery.EMPTY_STRING, 
atIndex: 0)
+            self.requirementStrings.insert(UsergridQuery.AND, at: 0)
+            self.requirementStrings.insert(UsergridQuery.EMPTY_STRING, at: 0)
         }
         return self
     }
@@ -303,10 +330,11 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
+    @discardableResult
     public func not() -> Self {
         if !self.requirementStrings.first!.isEmpty {
-            self.requirementStrings.insert(UsergridQuery.NOT, atIndex: 0)
-            self.requirementStrings.insert(UsergridQuery.EMPTY_STRING, 
atIndex: 0)
+            self.requirementStrings.insert(UsergridQuery.NOT, at: 0)
+            self.requirementStrings.insert(UsergridQuery.EMPTY_STRING, at: 0)
         }
         return self
     }
@@ -319,7 +347,8 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
-    public func sort(term: String, sortOrder: UsergridQuerySortOrder) -> Self {
+    @discardableResult
+    public func sort(_ term: String, sortOrder: UsergridQuerySortOrder) -> 
Self {
         self.orderClauses[term] = sortOrder
         return self
     }
@@ -331,7 +360,8 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
-    public func collection(collectionName: String) -> Self {
+    @discardableResult
+    public func collection(_ collectionName: String) -> Self {
         self.collectionName = collectionName
         return self
     }
@@ -343,7 +373,8 @@ public class UsergridQuery : NSObject,NSCopying {
 
      - returns: `Self`
      */
-    public func type(type: String) -> Self {
+    @discardableResult
+    public func type(_ type: String) -> Self {
         self.collectionName = type
         return self
     }
@@ -355,7 +386,8 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
-    public func limit(limit: Int) -> Self {
+    @discardableResult
+    public func limit(_ limit: Int) -> Self {
         self.limit = limit
         return self
     }
@@ -367,7 +399,8 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
-    public func ql(value: String) -> Self {
+    @discardableResult
+    public func ql(_ value: String) -> Self {
         return self.addRequirement(value)
     }
     
@@ -378,7 +411,8 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
-    public func cursor(value: String?) -> Self {
+    @discardableResult
+    public func cursor(_ value: String?) -> Self {
         self.cursor = value
         return self
     }
@@ -390,7 +424,8 @@ public class UsergridQuery : NSObject,NSCopying {
 
      - returns: `Self`
      */
-    public func fromString(value: String?) -> Self {
+    @discardableResult
+    public func fromString(_ value: String?) -> Self {
         self.fromStringValue = value
         return self
     }
@@ -403,11 +438,12 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
-    public func urlTerm(term: String, equalsValue: String) -> Self {
-        if (term as NSString).isEqualToString(UsergridQuery.QL) {
-            self.ql(equalsValue)
+    @discardableResult
+    public func urlTerm(_ term: String, equalsValue: String) -> Self {
+        if term == UsergridQuery.QL {
+            return self.ql(equalsValue)
         } else {
-            self.urlTerms.append(term + 
UsergridQueryOperator.Equal.stringValue + equalsValue)
+            self.urlTerms.append(term + 
UsergridQueryOperator.equal.stringValue + equalsValue)
         }
         return self
     }
@@ -421,7 +457,8 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
-    public func addOperationRequirement(term: String, operation: 
UsergridQueryOperator, stringValue: String) -> Self {
+    @discardableResult
+    public func addOperationRequirement(_ term: String, operation: 
UsergridQueryOperator, stringValue: String) -> Self {
         return 
self.addOperationRequirement(term,operation:operation,value:stringValue)
     }
     
@@ -434,25 +471,32 @@ public class UsergridQuery : NSObject,NSCopying {
      
      - returns: `Self`
      */
-    public func addOperationRequirement(term: String, operation: 
UsergridQueryOperator, intValue: Int) -> Self {
+    @discardableResult
+    public func addOperationRequirement(_ term: String, operation: 
UsergridQueryOperator, intValue: Int) -> Self {
         return 
self.addOperationRequirement(term,operation:operation,value:intValue)
     }
-    
-    private func addRequirement(requirement: String) -> Self {
-        var requirementString: String = 
self.requirementStrings.removeAtIndex(0)
+
+    @discardableResult
+    private func addRequirement(_ requirement: String) -> Self {
+        var requirementString: String = self.requirementStrings.remove(at: 0)
         if !requirementString.isEmpty {
             requirementString += UsergridQuery.SPACE + UsergridQuery.AND + 
UsergridQuery.SPACE
         }
         requirementString += requirement
-        self.requirementStrings.insert(requirementString, atIndex: 0)
+        self.requirementStrings.insert(requirementString, at: 0)
         return self
     }
-    
-    private func addOperationRequirement(term: String, operation: 
UsergridQueryOperator, value: AnyObject) -> Self {
-        if value is String {
-            return self.addRequirement(term + UsergridQuery.SPACE + 
operation.stringValue + UsergridQuery.SPACE + ((value.description.isUuid()) ? 
UsergridQuery.EMPTY_STRING : UsergridQuery.APOSTROPHE) + value.description + 
((value.description.isUuid()) ? UsergridQuery.EMPTY_STRING : 
UsergridQuery.APOSTROPHE) )
+
+    @discardableResult
+    private func addOperationRequirement(_ term: String, operation: 
UsergridQueryOperator, value: Any) -> Self {
+        if let stringValue = value as? String {
+            var operationValue: String = stringValue
+            if !stringValue.isUuid() {
+                operationValue = UsergridQuery.APOSTROPHE + stringValue + 
UsergridQuery.APOSTROPHE
+            }
+            return self.addRequirement(term + UsergridQuery.SPACE + 
operation.stringValue + UsergridQuery.SPACE + operationValue)
         } else {
-            return self.addRequirement(term + UsergridQuery.SPACE + 
operation.stringValue + UsergridQuery.SPACE + value.description)
+            return self.addRequirement(term + UsergridQuery.SPACE + 
operation.stringValue + UsergridQuery.SPACE + (value as AnyObject).description )
         }
     }
     
@@ -477,7 +521,7 @@ public class UsergridQuery : NSObject,NSCopying {
     }
     
     private func constructURLTermsString() -> String {
-        return (self.urlTerms as 
NSArray).componentsJoinedByString(UsergridQuery.AMPERSAND)
+        return self.urlTerms.joined(separator: UsergridQuery.AMPERSAND)
     }
     
     private func constructRequirementString() -> String {
@@ -485,25 +529,25 @@ public class UsergridQuery : NSObject,NSCopying {
         var requirementStrings = self.requirementStrings
         
         // If the first requirement is empty lets remove it.
-        if let firstRequirement = requirementStrings.first where 
firstRequirement.isEmpty {
+        if let firstRequirement = requirementStrings.first , 
firstRequirement.isEmpty {
             requirementStrings.removeFirst()
         }
         
         // If the first requirement now is a conditional separator then we 
should remove it so its not placed at the end of the constructed string.
-        if let firstRequirement = requirementStrings.first where 
firstRequirement == UsergridQuery.OR || firstRequirement == UsergridQuery.NOT {
+        if let firstRequirement = requirementStrings.first , firstRequirement 
== UsergridQuery.OR || firstRequirement == UsergridQuery.NOT {
             requirementStrings.removeFirst()
         }
         
-        requirementsString = (requirementStrings.reverse() as 
NSArray).componentsJoinedByString(UsergridQuery.SPACE)
+        requirementsString = requirementStrings.reversed().joined(separator: 
UsergridQuery.SPACE)
         return requirementsString
     }
     
-    private func constructURLAppend(autoURLEncode: Bool = true) -> String {
+    private func constructURLAppend(_ autoURLEncode: Bool = true) -> String {
 
         if let fromString = self.fromStringValue {
             var requirementsString = fromString
             if autoURLEncode {
-                if let encodedRequirementsString = 
fromString.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())
 {
+                if let encodedRequirementsString = 
fromString.addingPercentEncoding(withAllowedCharacters: 
CharacterSet.urlQueryAllowed) {
                     requirementsString = encodedRequirementsString
                 }
             }
@@ -521,7 +565,7 @@ public class UsergridQuery : NSObject,NSCopying {
             }
             urlAppend += urlTermsString
         }
-        if let cursorString = self.cursor where !cursorString.isEmpty {
+        if let cursorString = self.cursor , !cursorString.isEmpty {
             if !urlAppend.isEmpty {
                 urlAppend += UsergridQuery.AMPERSAND
             }
@@ -535,7 +579,7 @@ public class UsergridQuery : NSObject,NSCopying {
         }
         if !requirementsString.isEmpty {
             if autoURLEncode {
-                if let encodedRequirementsString = 
requirementsString.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())
 {
+                if let encodedRequirementsString = 
requirementsString.addingPercentEncoding(withAllowedCharacters: 
CharacterSet.urlQueryAllowed) {
                     requirementsString = encodedRequirementsString
                 }
             }

Reply via email to