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.18.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
heyzooi committed Jul 23, 2018
2 parents 7aa8a73 + f8530a0 commit a8ee482
Show file tree
Hide file tree
Showing 26 changed files with 453 additions and 4,202 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
language: objective-c
osx_image: xcode9.4
cache:
directories:
- Carthage
before_script:
- security create-keychain -p travis ios-build.keychain
- security default-keychain -s ios-build.keychain
Expand Down
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.18.0"
s.version = "3.18.1"
s.summary = "Kinvey iOS SDK"

# This description is used to generate tags and improve search results.
Expand Down
232 changes: 4 additions & 228 deletions Kinvey/Kinvey.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

83 changes: 52 additions & 31 deletions Kinvey/Kinvey/CustomEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,36 @@ import PromiseKit
/// Class to interact with a custom endpoint in the backend.
open class CustomEndpoint {

internal enum ParamsEnum {

case json(JsonDictionary)
case object(BaseMappable)
case jsonEncodable(JSONEncodable)

}

/// Parameter Wrapper
open class Params {

internal let value: ParamsEnum
internal let value: JsonDictionary

/**
Sets the `value` enumeration to a JSON dictionary.
- parameter json: JSON dictionary to be used as a parameter value
*/
public init(_ json: JsonDictionary) {
value = ParamsEnum.json(json)
value = json.toJson()
}

/**
Sets the `value` enumeration to any Mappable object.
- parameter object: Mappable object to be used as a parameter value
Sets the `value` enumeration to any Mappable object or StaticMappable struct.
- parameter object: Mappable object or StaticMappable struct to be used as a parameter value
*/
@available(*, deprecated: 3.18.0, message: "Please use Swift.Codable instead")
public init(_ object: Mappable) {
value = ParamsEnum.object(object)
public convenience init<T>(_ object: T) where T: BaseMappable {
self.init(object.toJSON())
}

/**
Sets the `value` enumeration to any StaticMappable struct.
- parameter object: StaticMappable struct to be used as a parameter value
*/
@available(*, deprecated: 3.18.0, message: "Please use Swift.Codable instead")
public init(_ object: StaticMappable) {
value = ParamsEnum.object(object)
public convenience init(_ object: JSONEncodable) throws {
self.init(try object.encode())
}

public init(_ object: JSONEncodable) {
value = ParamsEnum.jsonEncodable(object)
public convenience init<T>(_ object: T) throws where T: Encodable {
let data = try JSONEncoder().encode(object)
let json = try JSONSerialization.jsonObject(with: data) as! JsonDictionary
self.init(json)
}

}
Expand All @@ -75,14 +64,7 @@ open class CustomEndpoint {
resultType: resultType
)
if let params = params {
switch params.value {
case .json(let json):
request.setBody(json: json.toJson())
case .object(let object):
request.setBody(json: object.toJSON().toJson())
case .jsonEncodable(let jsonEncodable):
request.setBody(json: try! jsonEncodable.encode())
}
request.setBody(json: params.value)
}
request.request.setValue(nil, forHTTPHeaderField: KinveyHeaderField.requestId)
request.execute(completionHandler)
Expand Down Expand Up @@ -391,4 +373,43 @@ open class CustomEndpoint {
return request
}

/// Executes a custom endpoint by name and passing the expected parameters.
@discardableResult
open static func execute<T>(
_ name: String,
params: Params? = nil,
options: Options? = nil,
completionHandler: ((Result<[T], Swift.Error>) -> Void)? = nil
) -> AnyRequest<Result<[T], Swift.Error>> where T: Decodable {
let client = options?.client ?? sharedClient
var request: AnyRequest<Result<[T], Swift.Error>>!
Promise<[T]> { resolver in
request = callEndpoint(
name,
params: params,
options: options,
resultType: Result<[T], Swift.Error>.self
) { data, response, error in
do {
if let response = response,
response.isOK,
let data = data
{
let objArray = try JSONDecoder().decode([T].self, from: data)
resolver.fulfill(objArray)
} else {
resolver.reject(buildError(data, response, error, client))
}
} catch {
resolver.reject(error)
}
}
}.done { objArray in
completionHandler?(.success(objArray))
}.catch { error in
completionHandler?(.failure(error))
}
return request
}

}
2 changes: 1 addition & 1 deletion Kinvey/Kinvey/FindOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ internal class FindOperation<T: Persistable>: ReadOperation<T, AnyRandomAccessCo
if self.mustSaveQueryLastSync ?? true, let requestStart = response.requestStartHeader {
syncQuery = (query: self.query, lastSync: requestStart)
}
if let cache = cache.dynamic {
if !(T.self is Codable.Type), let cache = cache.dynamic {
cache.save(entities: AnyRandomAccessCollection(jsonArray), syncQuery: syncQuery)
} else {
cache.save(entities: entities, syncQuery: syncQuery)
Expand Down
17 changes: 0 additions & 17 deletions Kinvey/Kinvey/HttpRequestFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -809,23 +809,6 @@ class HttpRequestFactory: RequestFactory {
)
}

func buildLiveStreamGrantAccess<Result>(
streamName: String,
userId: String,
acl: LiveStreamAcl,
options: Options?,
resultType: Result.Type
) -> HttpRequest<Result> {
let request = HttpRequest<Result>(
httpMethod: .put,
endpoint: Endpoint.liveStreamByUser(client: options?.client ?? self.client, streamName: streamName, userId: userId),
credential: client.activeUser,
options: options
)
request.setBody(json: acl.toJSON())
return request
}

func buildLiveStreamAccess<Result>(
streamName: String,
userId: String,
Expand Down
2 changes: 1 addition & 1 deletion Kinvey/Kinvey/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>3.18.0</string>
<string>3.18.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
12 changes: 10 additions & 2 deletions Kinvey/Kinvey/RealmCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ internal class RealmCache<T: Persistable>: Cache<T>, CacheType where T: NSObject
var newEntity: Entity!
executor.executeAndWait {
try! self.write { realm in
if let entityId = entity.entityId, let oldEntity = realm.object(ofType: self.entityType, forPrimaryKey: entityId) {
self.cascadeDelete(realm: realm, entityType: self.entityTypeClassName, entity: oldEntity, deleteItself: false)
}
newEntity = realm.create((type(of: entity) as! Entity.Type), value: entity, update: true)
}
if let entity = entity as? Entity {
Expand All @@ -408,6 +411,9 @@ internal class RealmCache<T: Persistable>: Cache<T>, CacheType where T: NSObject
newEntities.reserveCapacity(entities.count)
try! self.write { realm in
for entity in entities {
if let entityId = entity.entityId, let oldEntity = realm.object(ofType: entityType, forPrimaryKey: entityId) {
self.cascadeDelete(realm: realm, entityType: self.entityTypeClassName, entity: oldEntity, deleteItself: false)
}
let newEntity = realm.create(entityType, value: entity, update: true)
newEntities.append(newEntity)
}
Expand Down Expand Up @@ -703,7 +709,7 @@ extension RealmSwift.NotificationToken: NotificationToken {

extension RealmCache: DynamicCacheType {

internal func cascadeDelete(realm: Realm, entityType: String, entity: Object) {
internal func cascadeDelete(realm: Realm, entityType: String, entity: Object, deleteItself: Bool = true) {
if let schema = realm.schema[entityType] {
schema.properties.forEachAutoreleasepool { property in
switch property.type {
Expand Down Expand Up @@ -734,7 +740,9 @@ extension RealmCache: DynamicCacheType {
}
}
}
realm.delete(entity)
if deleteItself {
realm.delete(entity)
}
}

private func cascadeDelete(realm: Realm, entityType: String, entities: List<DynamicObject>) {
Expand Down
13 changes: 13 additions & 0 deletions Kinvey/Kinvey/RealmSupport.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// RealmSupport.swift
// Kinvey
//
// Created by Victor Hugo Carvalho Barros on 2018-07-17.
// Copyright © 2018 Kinvey. All rights reserved.
//

import Realm

public typealias RLMRealm = Realm.RLMRealm
public typealias RLMObjectSchema = Realm.RLMObjectSchema
public typealias RLMSchema = Realm.RLMSchema
Loading

0 comments on commit a8ee482

Please sign in to comment.