Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Adding callback queue on .success #448

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
pull_request:
branches: '*'
env:
CI_XCODE_OLDEST: '/Applications/Xcode_12.5.1.app/Contents/Developer'
CI_XCODE_OLDEST: '/Applications/Xcode_13.1.app/Contents/Developer'
CI_XCODE_13: '/Applications/Xcode_13.4.1.app/Contents/Developer'
CI_XCODE_LATEST: '/Applications/Xcode_14.0.1.app/Contents/Developer'

Expand Down
2 changes: 2 additions & 0 deletions Sources/ParseSwift/API/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,5 @@ public struct API {
ParseConstants.sdk+ParseConstants.version
}
}

// swiftlint:enable line_length
2 changes: 1 addition & 1 deletion Sources/ParseSwift/API/BatchUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ typealias RESTBatchCommandNoBodyType<T> = API.NonParseBodyCommand<ParseObjectBat

typealias ParseObjectBatchCommandEncodablePointer<T> = BatchChildCommand<T, PointerType> where T: Encodable
typealias ParseObjectBatchResponseEncodablePointer<U> = [(Result<PointerType, ParseError>)]
// swiftlint:disable line_length

typealias RESTBatchCommandTypeEncodablePointer<T> = API.NonParseBodyCommand<ParseObjectBatchCommandEncodablePointer<T>, ParseObjectBatchResponseEncodablePointer<Encodable>> where T: Encodable
// swiftlint:enable line_length

Expand Down
3 changes: 1 addition & 2 deletions Sources/ParseSwift/API/ParseURLSessionDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import Foundation
import FoundationNetworking
#endif

class ParseURLSessionDelegate: NSObject
{
class ParseURLSessionDelegate: NSObject {
var callbackQueue: DispatchQueue
var authentication: ((URLAuthenticationChallenge,
(URLSession.AuthChallengeDisposition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,5 @@ public extension ParseUser {
Self.apple
}
}

// swiftlint:enable line_length
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,5 @@ public extension ParseUser {
Self.facebook
}
}

// swiftlint:enable line_length
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,5 @@ public extension ParseUser {
Self.github
}
}

// swiftlint:enable line_length
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,5 @@ public extension ParseUser {
Self.google
}
}

// swiftlint:enable line_length
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,5 @@ public extension ParseUser {
Self.instagram
}
}

// swiftlint:enable line_length
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,5 @@ public extension ParseUser {
Self.ldap
}
}

// swiftlint:enable line_length
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,5 @@ public extension ParseUser {
Self.linkedin
}
}

// swiftlint:enable line_length
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,5 @@ public extension ParseUser {
Self.spotify
}
}

// swiftlint:enable line_length
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,6 @@ public extension ParseUser {
Self.twitter
}
}

// swiftlint:enable line_length
// swiftlint:enable function_parameter_count
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,5 @@ public extension ParseUser {
}
}
}

// swiftlint:enable line_length
2 changes: 2 additions & 0 deletions Sources/ParseSwift/Coding/AnyDecodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct AnyDecodable: Decodable {
}
}

// swiftlint:disable type_name
protocol _AnyDecodable {
var value: Any { get }
init<T>(_ value: T?)
Expand Down Expand Up @@ -72,6 +73,7 @@ extension _AnyDecodable {
}
}
}
// swiftlint:enable type_name

extension AnyDecodable: Equatable {
static func == (lhs: AnyDecodable, rhs: AnyDecodable) -> Bool {
Expand Down
2 changes: 2 additions & 0 deletions Sources/ParseSwift/Coding/AnyEncodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct AnyEncodable: Encodable {
}
}

// swiftlint:disable type_name
@usableFromInline
protocol _AnyEncodable {

Expand All @@ -49,6 +50,7 @@ extension AnyEncodable: _AnyEncodable {}
// MARK: - Encodable

extension _AnyEncodable {
// swiftlint:enable type_name
// swiftlint:disable:next cyclomatic_complexity function_body_length
func encode(to encoder: Encoder) throws {

Expand Down
38 changes: 25 additions & 13 deletions Sources/ParseSwift/Coding/ParseEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
//
//===----------------------------------------------------------------------===//

// This rule does not allow types with underscores in their names.
// swiftlint:disable type_name
// swiftlint:disable colon
// swiftlint:disable line_length
// swiftlint:disable return_arrow_whitespace
// swiftlint:disable file_length
// swiftlint:disable redundant_discardable_let
// swiftlint:disable cyclomatic_complexity

import Foundation

/// A marker protocol used to determine whether a value is a `String`-keyed `Dictionary`
Expand All @@ -34,16 +43,6 @@
#endif
extension Dictionary: _JSONStringDictionaryEncodableMarker where Key == String, Value: Encodable { }

// This rule does not allow types with underscores in their names.
// swiftlint:disable type_name
// swiftlint:disable colon
// swiftlint:disable force_cast
// swiftlint:disable line_length
// swiftlint:disable return_arrow_whitespace
// swiftlint:disable file_length
// swiftlint:disable redundant_discardable_let
// swiftlint:disable cyclomatic_complexity

// MARK: ParseEncoder
/** An object that encodes Parse instances of a data type as JSON objects.
- note: `JSONEncoder` facilitates the encoding of `Encodable` values into JSON.
Expand Down Expand Up @@ -170,6 +169,7 @@
objectsSavedBeforeThisOne: objectsSavedBeforeThisOne,
filesSavedBeforeThisOne: filesSavedBeforeThisOne)
}
// swiftlint:enable large_tuple

// swiftlint:disable large_tuple
internal func encode(_ value: ParseEncodable,
Expand Down Expand Up @@ -197,6 +197,7 @@
objectsSavedBeforeThisOne: objectsSavedBeforeThisOne,
filesSavedBeforeThisOne: filesSavedBeforeThisOne)
}
// swiftlint:enable large_tuple
}

// MARK: _ParseEncoder
Expand Down Expand Up @@ -260,6 +261,7 @@
message: "This method should not be used. Either use the JSONEncoder or if you are encoding a ParseObject use \"encodeObject\"")
}

// swiftlint:disable large_tuple
func encodeObject(_ value: Encodable,
batching: Bool = false,
collectChildren: Bool,
Expand Down Expand Up @@ -294,6 +296,7 @@
EncodingError.Context(codingPath: [], debugDescription: "Unable to encode the given top-level value to JSON.", underlyingError: error))
}
}
// swiftlint:enable large_tuple

func container<Key>(keyedBy type: Key.Type) -> KeyedEncodingContainer<Key> where Key: CodingKey {

Expand Down Expand Up @@ -545,6 +548,7 @@
existingContainer is NSMutableDictionary,
"Attempt to re-encode into nested KeyedEncodingContainer<\(Key.self)> for key \"\(containerKey)\" is invalid: non-keyed container already encoded for this key"
)
// swiftlint:disable:next force_cast
dictionary = existingContainer as! NSMutableDictionary
} else {
dictionary = NSMutableDictionary()
Expand All @@ -567,6 +571,7 @@
existingContainer is NSMutableArray,
"Attempt to re-encode into nested UnkeyedEncodingContainer for key \"\(containerKey)\" is invalid: keyed container/single value already encoded for this key"
)
// swiftlint:disable:next force_cast

Check warning on line 574 in Sources/ParseSwift/Coding/ParseEncoder.swift

View check run for this annotation

Codecov / codecov/patch

Sources/ParseSwift/Coding/ParseEncoder.swift#L574

Added line #L574 was not covered by tests
array = existingContainer as! NSMutableArray
} else {
array = NSMutableArray()
Expand Down Expand Up @@ -759,7 +764,6 @@
}

// MARK: - Concrete Value Representations
// swiftlint:disable force_cast
extension _ParseEncoder {
/// Returns the given value boxed in a container appropriate for pushing onto the container stack.
func box(_ value: Bool) -> NSObject { return NSNumber(value: value) }
Expand Down Expand Up @@ -941,14 +945,14 @@
return try self.box_(value) ?? NSDictionary()
}

// swiftlint:disable:next line_length
// This method is called "box_" instead of "box" to disambiguate it from the overloads. Because the return type here is different from all of the "box" overloads (and is more general), any "box" calls in here would call back into "box" recursively instead of calling the appropriate overload, which is not what we want.
func box_(_ value: Encodable) throws -> NSObject? {
// Disambiguation between variable and function is required due to
// issue tracked at: https://bugs.swift.org/browse/SR-1846
let type = Swift.type(of: value)
if type == Date.self || type == NSDate.self {
// Respect Date encoding strategy
// swiftlint:disable:next force_cast
return try self.box((value as! Date))
} else if type == Data.self || type == NSData.self {
// Respect Data encoding strategy
Expand Down Expand Up @@ -992,6 +996,7 @@
return self.storage.popContainer()
}
}
// swiftlint:enable line_length

// MARK: - _ParseReferencingEncoder
// swiftlint:disable line_length
Expand Down Expand Up @@ -1173,11 +1178,18 @@
//===----------------------------------------------------------------------===//
// Shared ISO8601 Date Formatter
//===----------------------------------------------------------------------===//
// swiftlint:disable:next line_length
// NOTE: This value is implicitly lazy and _must_ be lazy. We're compiled against the latest SDK (w/ ISO8601DateFormatter), but linked against whichever Foundation the user has. ISO8601DateFormatter might not exist, so we better not hit this code path on an older OS.
@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
private var _iso8601Formatter: ISO8601DateFormatter = {
let formatter = ISO8601DateFormatter()
formatter.formatOptions = .withInternetDateTime
return formatter
}()

// swiftlint:enable type_name
// swiftlint:enable colon
// swiftlint:enable line_length
// swiftlint:enable return_arrow_whitespace
// swiftlint:enable file_length
// swiftlint:enable redundant_discardable_let
// swiftlint:enable cyclomatic_complexity
24 changes: 14 additions & 10 deletions Sources/ParseSwift/Extensions/URLSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,13 @@ internal extension URLSession {

dataTask(with: request) { (responseData, urlResponse, responseError) in
guard let httpResponse = urlResponse as? HTTPURLResponse else {
completion(self.makeResult(request: request,
responseData: responseData,
urlResponse: urlResponse,
responseError: responseError,
mapper: mapper))
callbackQueue.async {
completion(self.makeResult(request: request,
responseData: responseData,
urlResponse: urlResponse,
responseError: responseError,
mapper: mapper))
}
return
}
let statusCode = httpResponse.statusCode
Expand All @@ -207,11 +209,13 @@ internal extension URLSession {
}
return
}
completion(self.makeResult(request: request,
responseData: responseData,
urlResponse: urlResponse,
responseError: responseError,
mapper: mapper))
callbackQueue.async {
completion(self.makeResult(request: request,
responseData: responseData,
urlResponse: urlResponse,
responseError: responseError,
mapper: mapper))
}
}.resume()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,5 @@ public extension ParseLiveQueryDelegate {
func closedSocket(_ code: URLSessionWebSocketTask.CloseCode?, reason: Data?) { }
}
#endif

// swiftlint:enable line_length
Loading
Loading