Skip to content
This repository has been archived by the owner on Feb 13, 2025. It is now read-only.

Commit

Permalink
Merge branch 'release/3.13.0'
Browse files Browse the repository at this point in the history
# Conflicts:
#	Kinvey/KinveyTests/UserTests.swift
  • Loading branch information
heyzooi committed Mar 15, 2018
2 parents 85a11ce + 2013db0 commit b903616
Show file tree
Hide file tree
Showing 19 changed files with 737 additions and 188 deletions.
8 changes: 4 additions & 4 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
github "DaveWoodCom/XCGLogger" "6.0.2"
github "Hearst-DD/ObjectMapper" "3.1.0"
github "Quick/Nimble" "v7.0.3"
github "glock45/swifter" "1.3.3"
github "kif-framework/KIF" "v3.6.0"
github "glock45/swifter" "1.4.0"
github "kif-framework/KIF" "v3.7.1"
github "kishikawakatsumi/KeychainAccess" "v3.1.0"
github "mxcl/PromiseKit" "4.5.2"
github "pubnub/objective-c" "v4.7.6"
github "realm/realm-cocoa" "v3.1.1"
github "pubnub/objective-c" "v4.7.7"
github "realm/realm-cocoa" "v3.2.0"
github "tjboneman/NSPredicate-MongoDB-Adaptor" "3659f0846c983498c34310de21773f29668b2bd0"
2 changes: 1 addition & 1 deletion Kinvey.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "Kinvey"
s.version = "3.12.2"
s.version = "3.13.0"
s.summary = "Kinvey iOS SDK"

# This description is used to generate tags and improve search results.
Expand Down
20 changes: 12 additions & 8 deletions Kinvey/Kinvey/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ open class Client: Credential {
if let sharedKeychain = sharedKeychain {
try! sharedKeychain.removeAll()
}
dataStoreInstances.removeAll()
} else {
if let sharedKeychain = sharedKeychain {
try! sharedKeychain.removeAll()
Expand Down Expand Up @@ -91,7 +90,17 @@ open class Client: Credential {

/// Timeout interval for this client instance.
@available(*, deprecated: 3.12.2, message: "Please use `options` instead")
open var timeoutInterval: TimeInterval = 60
open var timeoutInterval: TimeInterval {
get {
return options?.timeout ?? Client.urlSessionConfiguration.timeoutIntervalForRequest
}
set {
if options == nil {
options = Options()
}
options?.timeout = newValue
}
}

/**
Hold default optional values for all calls made by this `Client` instance
Expand Down Expand Up @@ -124,13 +133,11 @@ open class Client: Credential {
///Default Value for DataStore tag
open static let defaultTag = Kinvey.defaultTag

var dataStoreInstances = [DataStoreTypeTag : AnyObject]()

/// Enables logging for any network calls.
open var logNetworkEnabled = false

/// Stores the MIC API Version to be used in MIC calls
open var micApiVersion: MICApiVersion? = .v1
open var micApiVersion: MICApiVersion? = .v3

/// Default constructor. The `initialize` method still need to be called after instanciate a new instance.
public init() {
Expand Down Expand Up @@ -340,9 +347,6 @@ open class Client: Credential {
self.encryptionKey = encryptionKey
self.schemaVersion = schema?.version ?? 0
self.options = options
if let timeout = options?.timeout {
self.timeoutInterval = timeout
}

Migration.performMigration(persistenceId: appKey, encryptionKey: encryptionKey, schemaVersion: schemaVersion, migrationHandler: schema?.migrationHandler)

Expand Down
56 changes: 11 additions & 45 deletions Kinvey/Kinvey/DataStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,6 @@
import Foundation
import PromiseKit

class DataStoreTypeTag: Hashable {

let persistableType: Persistable.Type
let tag: String
let type: StoreType

init(persistableType: Persistable.Type, tag: String, type: StoreType) {
self.persistableType = persistableType
self.tag = tag
self.type = type
}

var hashValue: Int {
var hash = NSDecimalNumber(value: 5)
hash = 23 * hash + NSDecimalNumber(value: NSStringFromClass(persistableType as! AnyClass).hashValue)
hash = 23 * hash + NSDecimalNumber(value: tag.hashValue)
hash = 23 * hash + NSDecimalNumber(value: type.hashValue)
return hash.hashValue
}

}

func +(lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> NSDecimalNumber {
return lhs.adding(rhs)
}
Expand All @@ -39,12 +17,6 @@ func *(lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> NSDecimalNumber {
return lhs.multiplying(by: rhs)
}

func ==(lhs: DataStoreTypeTag, rhs: DataStoreTypeTag) -> Bool {
return lhs.persistableType == rhs.persistableType &&
lhs.tag == rhs.tag &&
lhs.type == rhs.type
}

/// Class to interact with a specific collection in the backend.
open class DataStore<T: Persistable> where T: NSObject {

Expand Down Expand Up @@ -73,7 +45,7 @@ open class DataStore<T: Persistable> where T: NSObject {
internal let cache: AnyCache<T>?
internal let sync: AnySync?

fileprivate var deltaSet: Bool
open fileprivate(set) var deltaSet: Bool

fileprivate let uuid = UUID()

Expand Down Expand Up @@ -136,22 +108,16 @@ open class DataStore<T: Persistable> where T: NSObject {
if !client.isInitialized() {
fatalError("Client is not initialized. Call Kinvey.sharedClient.initialize(...) to initialize the client before creating a DataStore.")
}
let key = DataStoreTypeTag(persistableType: T.self, tag: tag, type: type)
var dataStore = client.dataStoreInstances[key] as? DataStore
if dataStore == nil {
let fileURL = client.fileURL(tag)
dataStore = DataStore<T>(
type: type,
deltaSet: deltaSet ?? false,
autoPagination: autoPagination,
client: client,
fileURL: fileURL,
encryptionKey: client.encryptionKey,
validationStrategy: validationStrategy
)
client.dataStoreInstances[key] = dataStore
}
return dataStore!
let fileURL = client.fileURL(tag)
return DataStore<T>(
type: type,
deltaSet: deltaSet ?? false,
autoPagination: autoPagination,
client: client,
fileURL: fileURL,
encryptionKey: client.encryptionKey,
validationStrategy: validationStrategy
)
}

/**
Expand Down
14 changes: 10 additions & 4 deletions Kinvey/Kinvey/Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public enum Error: Swift.Error, LocalizedError, CustomStringConvertible, CustomD

case entityNotFound(debug: String, description: String)

case invalidCredentials(httpResponse: HTTPURLResponse?, data: Data?, debug: String, description: String)

/// Error localized description.
public var description: String {
let bundle = Bundle(for: Client.self)
Expand All @@ -96,7 +98,8 @@ public enum Error: Swift.Error, LocalizedError, CustomStringConvertible, CustomD
.appNotFound(let description),
.forbidden(let description),
.resultSetSizeExceeded(_, let description),
.entityNotFound(_, let description):
.entityNotFound(_, let description),
.invalidCredentials(_, _, _, let description):
return description
case .objectIdMissing:
return NSLocalizedString("Error.objectIdMissing", bundle: bundle, comment: "")
Expand Down Expand Up @@ -134,7 +137,8 @@ public enum Error: Swift.Error, LocalizedError, CustomStringConvertible, CustomD
.missingConfiguration(_, _, let debug, _),
.unauthorized(_, _, _, let debug, _),
.resultSetSizeExceeded(let debug, _),
.entityNotFound(let debug, _):
.entityNotFound(let debug, _),
.invalidCredentials(_, _, let debug, _):
return debug
default:
return description
Expand All @@ -149,7 +153,8 @@ public enum Error: Swift.Error, LocalizedError, CustomStringConvertible, CustomD
.dataLinkEntityNotFound(let httpResponse, _, _, _),
.methodNotAllowed(let httpResponse, _, _, _),
.unauthorized(let httpResponse, _, _, _, _),
.invalidResponse(let httpResponse, _):
.invalidResponse(let httpResponse, _),
.invalidCredentials(let httpResponse, _, _, _):
return httpResponse
default:
return nil
Expand All @@ -170,7 +175,8 @@ public enum Error: Swift.Error, LocalizedError, CustomStringConvertible, CustomD
.methodNotAllowed(_, let data, _, _),
.unauthorized(_, let data, _, _, _),
.invalidResponse(_, let data),
.missingConfiguration(_, let data, _, _):
.missingConfiguration(_, let data, _, _),
.invalidCredentials(_, let data, _, _):
return data
default:
return nil
Expand Down
Loading

0 comments on commit b903616

Please sign in to comment.