diff --git a/stone/backends/swift_rsrc/ObjCRoutes.jinja b/stone/backends/swift_rsrc/ObjCRoutes.jinja index 84819924..0fd8de10 100644 --- a/stone/backends/swift_rsrc/ObjCRoutes.jinja +++ b/stone/backends/swift_rsrc/ObjCRoutes.jinja @@ -104,12 +104,29 @@ public class {{ fmt_route_objc_class(namespace, route, args_data) }}: NSObject, self.response(queue: nil, completionHandler: completionHandler) } + {% if route.attrs.get('style') == 'rpc' and ('user' in route.attrs.get('auth') or 'noauth' in route.attrs.get('auth')) and not route.deprecated %} @objc @discardableResult public func response( queue: DispatchQueue?, completionHandler: @escaping ({{ result_type }}) -> Void ) -> Self { + self.response(queue: nil, analyticsBlock: nil, completionHandler: completionHandler) + } + {% endif %} + + @objc + @discardableResult public func response( + queue: DispatchQueue? = nil, + {% if route.attrs.get('style') == 'rpc' and ('user' in route.attrs.get('auth') or 'noauth' in route.attrs.get('auth')) and not route.deprecated %} + analyticsBlock: AnalyticsBlock? = nil, + {% endif %} + completionHandler: @escaping ({{ result_type }}) -> Void + ) -> Self { + {% if route.attrs.get('style') == 'rpc' and ('user' in route.attrs.get('auth') or 'noauth' in route.attrs.get('auth')) and not route.deprecated %} + swift.response(queue: queue, analyticsBlock: analyticsBlock) { result, error in + {% else %} swift.response(queue: queue) { result, error in + {% endif %} {% if route.error_data_type.name != 'Void' %} {% set error_type = 'DBX' + fmt_class(route.error_data_type.namespace.name) + fmt_class(route.error_data_type.name) %} {% set error_call = 'routeError, callError' %} diff --git a/stone/backends/swift_rsrc/SwiftObjcShimHelpers.jinja b/stone/backends/swift_rsrc/SwiftObjcShimHelpers.jinja index 51451da8..739ec802 100644 --- a/stone/backends/swift_rsrc/SwiftObjcShimHelpers.jinja +++ b/stone/backends/swift_rsrc/SwiftObjcShimHelpers.jinja @@ -13,7 +13,8 @@ import stone_sdk_swift_objc public class SDKShimHelpers: NSObject { // MARK: DBAPIRpcTask - @objc public static func setResponseBlockRPC(block: @escaping DBRpcResponseBlockImpl, on task: DBXRequest, with queue: OperationQueue?) -> Bool { + @objc + @discardableResult public static func setResponseBlockRPC(block: @escaping DBRpcResponseBlockImpl, on task: DBXRequest, with queue: OperationQueue?, analyticsBlock: AnalyticsBlock?) -> Bool { {% for namespace in namespaces | selectattr('name', '!=', 'team') %} {% for route in namespace.routes %} {% if route.attrs.get('style') == 'rpc' and ('user' in route.attrs.get('auth') or 'noauth' in route.attrs.get('auth')) and not route.deprecated %} @@ -22,21 +23,21 @@ public class SDKShimHelpers: NSObject { {% set objc_error_mapper = objc_to_legacy_objc_mapper(route.error_data_type, 'routeError') %} if let task = task as? {{ objc_request_class }} { {% if route.result_data_type.name == 'Void' and route.error_data_type.name == 'Void' %} - task.response { networkError in + task.response(analyticsBlock: analyticsBlock) { networkError in let mappedCallError = callErrorToDB(error: networkError) let wrappedBlock = { block(networkError == nil ? DBNilObject() : nil, nil, mappedCallError) } {% elif route.result_data_type.name == 'Void' %} - task.response { routeError, networkError in + task.response(analyticsBlock: analyticsBlock) { routeError, networkError in let mappedError = {{ objc_error_mapper }} let mappedCallError = callErrorToDB(error: networkError) let wrappedBlock = { block((networkError == nil && routeError == nil) ? DBNilObject() : nil, mappedError, mappedCallError) } {% elif route.error_data_type.name == 'Void' %} - task.response { result, networkError in + task.response(analyticsBlock: analyticsBlock) { result, networkError in let mappedResult = {{ objc_result_mapper }} let mappedCallError = callErrorToDB(error: networkError) let wrappedBlock = { block(mappedResult, nil, mappedCallError) } {% else %} - task.response { result, routeError, networkError in + task.response(analyticsBlock: analyticsBlock) { result, routeError, networkError in let mappedResult = {{ objc_result_mapper }} let mappedError = {{ objc_error_mapper }} let mappedCallError = callErrorToDB(error: networkError)