From 14f401b9af1fd4298305631a2ac0e7643570586d Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Mon, 1 Feb 2021 14:48:51 -0500 Subject: [PATCH 1/8] Working on all except for user --- .../Contents.swift | 50 +++++++++++++++++- .../Contents.swift | 48 +++++++++++++++++ Sources/ParseSwift/API/API+Commands.swift | 13 +++-- .../Objects/ParseInstallation+combine.swift | 20 +++++--- .../Objects/ParseInstallation.swift | 51 ++++++++++++++----- .../Objects/ParseObject+combine.swift | 20 +++++--- Sources/ParseSwift/Objects/ParseObject.swift | 41 ++++++++++----- .../Objects/ParseUser+combine.swift | 20 +++++--- Sources/ParseSwift/Objects/ParseUser.swift | 49 +++++++++++++----- Sources/ParseSwift/Protocols/Fetchable.swift | 4 +- Sources/ParseSwift/Types/ParseFile.swift | 3 +- Sources/ParseSwift/Types/Pointer.swift | 2 +- Tests/ParseSwiftTests/ParseCloudTests.swift | 2 +- Tests/ParseSwiftTests/ParseConfigTests.swift | 2 +- .../ParseInstallationTests.swift | 36 ++++++++++++- .../ParseObjectBatchTests.swift | 2 +- Tests/ParseSwiftTests/ParseObjectTests.swift | 36 ++++++++++++- Tests/ParseSwiftTests/ParsePointerTests.swift | 2 +- Tests/ParseSwiftTests/ParseSessionTests.swift | 2 +- Tests/ParseSwiftTests/ParseUserTests.swift | 37 +++++++++++++- 20 files changed, 367 insertions(+), 73 deletions(-) diff --git a/ParseSwift.playground/Pages/4 - User - Continued.xcplaygroundpage/Contents.swift b/ParseSwift.playground/Pages/4 - User - Continued.xcplaygroundpage/Contents.swift index f282f6d7d..5136ddb4c 100644 --- a/ParseSwift.playground/Pages/4 - User - Continued.xcplaygroundpage/Contents.swift +++ b/ParseSwift.playground/Pages/4 - User - Continued.xcplaygroundpage/Contents.swift @@ -22,6 +22,29 @@ struct User: ParseUser { //: Your custom keys. var customKey: String? + var score: GameScore? + var targetScore: GameScore? +} + +//: Create your own value typed `ParseObject`. +struct GameScore: ParseObject { + //: Those are required for Object + var objectId: String? + var createdAt: Date? + var updatedAt: Date? + var ACL: ParseACL? + + //: Your own properties. + var score: Int? = 0 + + //: Custom initializer. + init(score: Int) { + self.score = score + } + + init(objectId: String?) { + self.objectId = objectId + } } /*: Save your first customKey value to your `ParseUser` @@ -30,11 +53,13 @@ struct User: ParseUser { If no callbackQueue is specified it returns to main queue. */ User.current?.customKey = "myCustom" +User.current?.score = GameScore(score: 12) +User.current?.targetScore = GameScore(score: 100) User.current?.save { results in switch results { case .success(let updatedUser): - print("Successfully save myCustomKey to ParseServer: \(updatedUser)") + print("Successfully save myCustomKey and score to ParseServer: \(updatedUser)") case .failure(let error): print("Failed to update user: \(error)") } @@ -69,6 +94,29 @@ User.login(username: "hello", password: "world") { results in } } +//: Looking at the output of user from the previous login, it only has +//: a pointer to the `score`and `targetScore` fields. You can fetch using `include` to +//: get the score. +User.current?.fetch(includeKeys: ["score"]) { result in + switch result { + case .success: + print("Successfully fetched user with score key: \(User.current)") + case .failure(let error): + print("Error fetching score: \(error)") + } +} + +//: The `target` score is still missing. You can get all pointer fields at +//: once by including `["*"]`. +User.current?.fetch(includeKeys: ["*"]) { result in + switch result { + case .success: + print("Successfully fetched user with all keys: \(User.current)") + case .failure(let error): + print("Error fetching score: \(error)") + } +} + //: Logging out - synchronously. do { try User.logout() diff --git a/ParseSwift.playground/Pages/6 - Installation.xcplaygroundpage/Contents.swift b/ParseSwift.playground/Pages/6 - Installation.xcplaygroundpage/Contents.swift index eb1b14b3f..797434ea6 100644 --- a/ParseSwift.playground/Pages/6 - Installation.xcplaygroundpage/Contents.swift +++ b/ParseSwift.playground/Pages/6 - Installation.xcplaygroundpage/Contents.swift @@ -29,6 +29,29 @@ struct Installation: ParseInstallation { //: Your custom keys var customKey: String? + var score: GameScore? + var targetScore: GameScore? +} + +//: Create your own value typed `ParseObject`. +struct GameScore: ParseObject { + //: Those are required for Object + var objectId: String? + var createdAt: Date? + var updatedAt: Date? + var ACL: ParseACL? + + //: Your own properties. + var score: Int? = 0 + + //: Custom initializer. + init(score: Int) { + self.score = score + } + + init(objectId: String?) { + self.objectId = objectId + } } //: WARNING: All calls on Installation need to be done on the main queue @@ -40,6 +63,8 @@ DispatchQueue.main.async { returns to main queue. */ Installation.current?.customKey = "myCustomInstallationKey2" + Installation.current?.score = GameScore(score: 12) + Installation.current?.targetScore = GameScore(score: 100) Installation.current?.save { results in switch results { @@ -49,6 +74,29 @@ DispatchQueue.main.async { assertionFailure("Failed to update installation: \(error)") } } + + //: Looking at the output of user from the previous login, it only has + //: a pointer to the `score`and `targetScore` fields. You can fetch using `include` to + //: get the score. + Installation.current?.fetch(includeKeys: ["score"]) { result in + switch result { + case .success(let fetched): + print("Successfully fetched user with score key: \(fetched)") + case .failure(let error): + print("Error fetching score: \(error)") + } + } + + //: The `target` score is still missing. You can get all pointer fields at + //: once by including `["*"]`. + Installation.current?.fetch(includeKeys: ["*"]) { result in + switch result { + case .success(let fetched): + print("Successfully fetched user with all keys: \(fetched)") + case .failure(let error): + print("Error fetching score: \(error)") + } + } } PlaygroundPage.current.finishExecution() diff --git a/Sources/ParseSwift/API/API+Commands.swift b/Sources/ParseSwift/API/API+Commands.swift index a626a430a..e7597f186 100644 --- a/Sources/ParseSwift/API/API+Commands.swift +++ b/Sources/ParseSwift/API/API+Commands.swift @@ -240,7 +240,7 @@ internal extension API { } } urlRequest.httpMethod = method.rawValue - + print(urlRequest) return .success(urlRequest) } @@ -383,14 +383,21 @@ internal extension API.Command { } // MARK: Fetching - static func fetchCommand(_ object: T) throws -> API.Command where T: ParseObject { + static func fetchCommand(_ object: T, include: [String]?) throws -> API.Command where T: ParseObject { guard object.isSaved else { throw ParseError(code: .unknownError, message: "Cannot Fetch an object without id") } + var params: [String: String]? + if let includeParams = include { + let joined = includeParams.joined(separator: ",") + params = ["include": joined] + } + return API.Command( method: .GET, - path: object.endpoint + path: object.endpoint, + params: params ) { (data) -> T in try ParseCoding.jsonDecoder().decode(T.self, from: data) } diff --git a/Sources/ParseSwift/Objects/ParseInstallation+combine.swift b/Sources/ParseSwift/Objects/ParseInstallation+combine.swift index a3ab82a76..1025562e3 100644 --- a/Sources/ParseSwift/Objects/ParseInstallation+combine.swift +++ b/Sources/ParseSwift/Objects/ParseInstallation+combine.swift @@ -18,14 +18,18 @@ public extension ParseInstallation { /** Fetches the `ParseInstallation` *aynchronously* with the current data from the server and sets an error if one occurs. Publishes when complete. - + - parameter includeKeys: The name(s) of the key(s) to include that are + `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: A publisher that eventually produces a single value and then finishes or fails. - important: If an object fetched has the same objectId as current, it will automatically update the current. */ - func fetchPublisher(options: API.Options = []) -> Future { + func fetchPublisher(includeKeys: [String]? = nil, + options: API.Options = []) -> Future { Future { promise in - self.fetch(options: options, + self.fetch(includeKeys: includeKeys, + options: options, completion: promise) } } @@ -66,14 +70,18 @@ public extension Sequence where Element: ParseInstallation { /** Fetches a collection of installations *aynchronously* with the current data from the server and sets an error if one occurs. Publishes when complete. - + - parameter includeKeys: The name(s) of the key(s) to include that are + `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: A publisher that eventually produces a single value and then finishes or fails. - important: If an object fetched has the same objectId as current, it will automatically update the current. */ - func fetchAllPublisher(options: API.Options = []) -> Future<[(Result)], ParseError> { + func fetchAllPublisher(includeKeys: [String]? = nil, + options: API.Options = []) -> Future<[(Result)], ParseError> { Future { promise in - self.fetchAll(options: options, + self.fetchAll(includeKeys: includeKeys, + options: options, completion: promise) } } diff --git a/Sources/ParseSwift/Objects/ParseInstallation.swift b/Sources/ParseSwift/Objects/ParseInstallation.swift index 6da8db305..71a1d069e 100644 --- a/Sources/ParseSwift/Objects/ParseInstallation.swift +++ b/Sources/ParseSwift/Objects/ParseInstallation.swift @@ -338,13 +338,16 @@ extension ParseInstallation { /** Fetches the `ParseInstallation` *synchronously* with the current data from the server and sets an error if one occurs. - + - parameter includeKeys: The name(s) of the key(s) to include that are + `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - throws: An error of `ParseError` type. - important: If an object fetched has the same objectId as current, it will automatically update the current. */ - public func fetch(options: API.Options = []) throws -> Self { - let result: Self = try fetchCommand() + public func fetch(includeKeys: [String]? = nil, + options: API.Options = []) throws -> Self { + let result: Self = try fetchCommand(include: includeKeys) .execute(options: options, callbackQueue: .main) Self.updateKeychainIfNeeded([result]) return result @@ -352,7 +355,9 @@ extension ParseInstallation { /** Fetches the `ParseInstallation` *asynchronously* and executes the given callback block. - + - parameter includeKeys: The name(s) of the key(s) to include that are + `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - parameter callbackQueue: The queue to return to after completion. Default value of .main. @@ -361,12 +366,13 @@ extension ParseInstallation { - important: If an object fetched has the same objectId as current, it will automatically update the current. */ public func fetch( + includeKeys: [String]? = nil, options: API.Options = [], callbackQueue: DispatchQueue = .main, completion: @escaping (Result) -> Void ) { do { - try fetchCommand() + try fetchCommand(include: includeKeys) .executeAsync(options: options, callbackQueue: callbackQueue) { result in callbackQueue.async { @@ -387,13 +393,20 @@ extension ParseInstallation { } } - func fetchCommand() throws -> API.Command { + func fetchCommand(include: [String]?) throws -> API.Command { guard isSaved else { throw ParseError(code: .unknownError, message: "Cannot fetch an object without id") } + var params: [String: String]? + if let includeParams = include { + let joined = includeParams.joined(separator: ",") + params = ["include": joined] + } + return API.Command(method: .GET, - path: endpoint) { (data) -> Self in + path: endpoint, + params: params) { (data) -> Self in try ParseCoding.jsonDecoder().decode(Self.self, from: data) } } @@ -756,7 +769,9 @@ public extension Sequence where Element: ParseInstallation { /** Fetches a collection of installations *synchronously* all at once and throws an error if necessary. - + - parameter includeKeys: The name(s) of the key(s) to include that are + `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: Returns a Result enum with the object if a fetch was successful or a `ParseError` if it failed. @@ -765,12 +780,18 @@ public extension Sequence where Element: ParseInstallation { - warning: The order in which installations are returned are not guarenteed. You shouldn't expect results in any particular order. */ - func fetchAll(options: API.Options = []) throws -> [(Result)] { + func fetchAll(includeKeys: [String]? = nil, + options: API.Options = []) throws -> [(Result)] { if (allSatisfy { $0.className == Self.Element.className}) { let uniqueObjectIds = Set(compactMap { $0.objectId }) - let query = Self.Element.query(containedIn(key: "objectId", array: [uniqueObjectIds])) + var query = Self.Element.query(containedIn(key: "objectId", array: [uniqueObjectIds])) .limit(uniqueObjectIds.count) + + if let include = includeKeys { + query = query.include(include) + } + let fetchedObjects = try query.find(options: options) var fetchedObjectsToReturn = [(Result)]() @@ -793,7 +814,9 @@ public extension Sequence where Element: ParseInstallation { /** Fetches a collection of installations all at once *asynchronously* and executes the completion block when done. - + - parameter includeKeys: The name(s) of the key(s) to include that are + `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - parameter callbackQueue: The queue to return to after completion. Default value of .main. - parameter completion: The block to execute. @@ -803,13 +826,17 @@ public extension Sequence where Element: ParseInstallation { any particular order. */ func fetchAll( + includeKeys: [String]? = nil, options: API.Options = [], callbackQueue: DispatchQueue = .main, completion: @escaping (Result<[(Result)], ParseError>) -> Void ) { if (allSatisfy { $0.className == Self.Element.className}) { let uniqueObjectIds = Set(compactMap { $0.objectId }) - let query = Self.Element.query(containedIn(key: "objectId", array: [uniqueObjectIds])) + var query = Self.Element.query(containedIn(key: "objectId", array: [uniqueObjectIds])) + if let include = includeKeys { + query = query.include(include) + } query.find(options: options, callbackQueue: callbackQueue) { result in switch result { diff --git a/Sources/ParseSwift/Objects/ParseObject+combine.swift b/Sources/ParseSwift/Objects/ParseObject+combine.swift index 973fe4e43..f75bfa567 100644 --- a/Sources/ParseSwift/Objects/ParseObject+combine.swift +++ b/Sources/ParseSwift/Objects/ParseObject+combine.swift @@ -17,14 +17,18 @@ public extension ParseObject { /** Fetches the `ParseObject` *aynchronously* with the current data from the server and sets an error if one occurs. Publishes when complete. - + - parameter includeKeys: The name(s) of the key(s) to include that are + `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: A publisher that eventually produces a single value and then finishes or fails. - important: If an object fetched has the same objectId as current, it will automatically update the current. */ - func fetchPublisher(options: API.Options = []) -> Future { + func fetchPublisher(includeKeys: [String]? = nil, + options: API.Options = []) -> Future { Future { promise in - self.fetch(options: options, + self.fetch(includeKeys: includeKeys, + options: options, completion: promise) } } @@ -63,14 +67,18 @@ public extension Sequence where Element: ParseObject { /** Fetches a collection of objects *aynchronously* with the current data from the server and sets an error if one occurs. Publishes when complete. - + - parameter includeKeys: The name(s) of the key(s) to include that are + `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: A publisher that eventually produces a single value and then finishes or fails. - important: If an object fetched has the same objectId as current, it will automatically update the current. */ - func fetchAllPublisher(options: API.Options = []) -> Future<[(Result)], ParseError> { + func fetchAllPublisher(includeKeys: [String]? = nil, + options: API.Options = []) -> Future<[(Result)], ParseError> { Future { promise in - self.fetchAll(options: options, + self.fetchAll(includeKeys: includeKeys, + options: options, completion: promise) } } diff --git a/Sources/ParseSwift/Objects/ParseObject.swift b/Sources/ParseSwift/Objects/ParseObject.swift index 8703ae1c5..211362499 100644 --- a/Sources/ParseSwift/Objects/ParseObject.swift +++ b/Sources/ParseSwift/Objects/ParseObject.swift @@ -229,7 +229,9 @@ public extension Sequence where Element: ParseObject { /** Fetches a collection of objects *synchronously* all at once and throws an error if necessary. - + - parameter includeKeys: The name(s) of the key(s) to include that are + `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: Returns a Result enum with the object if a fetch was successful or a `ParseError` if it failed. @@ -237,12 +239,16 @@ public extension Sequence where Element: ParseObject { - warning: The order in which objects are returned are not guarenteed. You shouldn't expect results in any particular order. */ - func fetchAll(options: API.Options = []) throws -> [(Result)] { + func fetchAll(includeKeys: [String]? = nil, + options: API.Options = []) throws -> [(Result)] { if (allSatisfy { $0.className == Self.Element.className}) { let uniqueObjectIds = Set(compactMap { $0.objectId }) - let query = Self.Element.query(containedIn(key: "objectId", array: [uniqueObjectIds])) + var query = Self.Element.query(containedIn(key: "objectId", array: [uniqueObjectIds])) .limit(uniqueObjectIds.count) + if let include = includeKeys { + query = query.include(include) + } let fetchedObjects = try query.find(options: options) var fetchedObjectsToReturn = [(Result)]() @@ -264,7 +270,9 @@ public extension Sequence where Element: ParseObject { /** Fetches a collection of objects all at once *asynchronously* and executes the completion block when done. - + - parameter includeKeys: The name(s) of the key(s) to include that are + `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - parameter callbackQueue: The queue to return to after completion. Default value of .main. - parameter completion: The block to execute. @@ -273,13 +281,17 @@ public extension Sequence where Element: ParseObject { any particular order. */ func fetchAll( + includeKeys: [String]? = nil, options: API.Options = [], callbackQueue: DispatchQueue = .main, completion: @escaping (Result<[(Result)], ParseError>) -> Void ) { if (allSatisfy { $0.className == Self.Element.className}) { let uniqueObjectIds = Set(compactMap { $0.objectId }) - let query = Self.Element.query(containedIn(key: "objectId", array: [uniqueObjectIds])) + var query = Self.Element.query(containedIn(key: "objectId", array: [uniqueObjectIds])) + if let include = includeKeys { + query = query.include(include) + } query.find(options: options, callbackQueue: callbackQueue) { result in switch result { @@ -446,18 +458,22 @@ extension ParseObject { /** Fetches the `ParseObject` *synchronously* with the current data from the server and sets an error if one occurs. - + - parameter includeKeys: The name(s) of the key(s) to include that are + `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - throws: An error of `ParseError` type. */ - public func fetch(options: API.Options = []) throws -> Self { - try fetchCommand().execute(options: options, + public func fetch(includeKeys: [String]? = nil, + options: API.Options = []) throws -> Self { + try fetchCommand(include: includeKeys).execute(options: options, callbackQueue: .main) } /** Fetches the `ParseObject` *asynchronously* and executes the given callback block. - + - parameter includeKeys: The name(s) of the key(s) to include. Use `["*"]` to include + all keys. - parameter options: A set of header options sent to the server. Defaults to an empty set. - parameter callbackQueue: The queue to return to after completion. Default value of .main. @@ -465,12 +481,13 @@ extension ParseObject { It should have the following argument signature: `(Result)`. */ public func fetch( + includeKeys: [String]? = nil, options: API.Options = [], callbackQueue: DispatchQueue = .main, completion: @escaping (Result) -> Void ) { do { - try fetchCommand() + try fetchCommand(include: includeKeys) .executeAsync(options: options, callbackQueue: callbackQueue) { result in callbackQueue.async { @@ -488,8 +505,8 @@ extension ParseObject { } } - internal func fetchCommand() throws -> API.Command { - try API.Command.fetchCommand(self) + internal func fetchCommand(include: [String]?) throws -> API.Command { + try API.Command.fetchCommand(self, include: include) } } diff --git a/Sources/ParseSwift/Objects/ParseUser+combine.swift b/Sources/ParseSwift/Objects/ParseUser+combine.swift index 3b02f554a..2f5b2d06b 100644 --- a/Sources/ParseSwift/Objects/ParseUser+combine.swift +++ b/Sources/ParseSwift/Objects/ParseUser+combine.swift @@ -140,14 +140,18 @@ public extension ParseUser { /** Fetches the `ParseUser` *aynchronously* with the current data from the server and sets an error if one occurs. Publishes when complete. - + - parameter includeKeys: The name(s) of the key(s) to include that are + `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: A publisher that eventually produces a single value and then finishes or fails. - important: If an object fetched has the same objectId as current, it will automatically update the current. */ - func fetchPublisher(options: API.Options = []) -> Future { + func fetchPublisher(includeKeys: [String]? = nil, + options: API.Options = []) -> Future { Future { promise in - self.fetch(options: options, + self.fetch(includeKeys: includeKeys, + options: options, completion: promise) } } @@ -188,14 +192,18 @@ public extension Sequence where Element: ParseUser { /** Fetches a collection of users *aynchronously* with the current data from the server and sets an error if one occurs. Publishes when complete. - + - parameter includeKeys: The name(s) of the key(s) to include that are + `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: A publisher that eventually produces a single value and then finishes or fails. - important: If an object fetched has the same objectId as current, it will automatically update the current. */ - func fetchAllPublisher(options: API.Options = []) -> Future<[(Result)], ParseError> { + func fetchAllPublisher(includeKeys: [String]? = nil, + options: API.Options = []) -> Future<[(Result)], ParseError> { Future { promise in - self.fetchAll(options: options, + self.fetchAll(includeKeys: includeKeys, + options: options, completion: promise) } } diff --git a/Sources/ParseSwift/Objects/ParseUser.swift b/Sources/ParseSwift/Objects/ParseUser.swift index b55adfbef..5c10be4c5 100644 --- a/Sources/ParseSwift/Objects/ParseUser.swift +++ b/Sources/ParseSwift/Objects/ParseUser.swift @@ -647,13 +647,16 @@ extension ParseUser { /** Fetches the `ParseUser` *synchronously* with the current data from the server and sets an error if one occurs. - + - parameter includeKeys: The name(s) of the key(s) to include that are + `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - throws: An error of `ParseError` type. - important: If an object fetched has the same objectId as current, it will automatically update the current. */ - public func fetch(options: API.Options = []) throws -> Self { - let result: Self = try fetchCommand() + public func fetch(includeKeys: [String]? = nil, + options: API.Options = []) throws -> Self { + let result: Self = try fetchCommand(include: includeKeys) .execute(options: options, callbackQueue: .main) try Self.updateKeychainIfNeeded([result]) @@ -662,7 +665,9 @@ extension ParseUser { /** Fetches the `ParseUser` *asynchronously* and executes the given callback block. - + - parameter includeKeys: The name(s) of the key(s) to include that are + `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - parameter callbackQueue: The queue to return to after completion. Default value of .main. @@ -671,12 +676,13 @@ extension ParseUser { - important: If an object fetched has the same objectId as current, it will automatically update the current. */ public func fetch( + includeKeys: [String]? = nil, options: API.Options = [], callbackQueue: DispatchQueue = .main, completion: @escaping (Result) -> Void ) { do { - try fetchCommand() + try fetchCommand(include: includeKeys) .executeAsync(options: options, callbackQueue: callbackQueue) { result in if case .success(let foundResult) = result { @@ -711,13 +717,20 @@ extension ParseUser { } } - func fetchCommand() throws -> API.Command { + func fetchCommand(include: [String]?) throws -> API.Command { guard isSaved else { throw ParseError(code: .unknownError, message: "Cannot fetch an object without id") } + var params: [String: String]? + if let includeParams = include { + let joined = includeParams.joined(separator: ",") + params = ["include": joined] + } + return API.Command(method: .GET, - path: endpoint) { (data) -> Self in + path: endpoint, + params: params) { (data) -> Self in try ParseCoding.jsonDecoder().decode(Self.self, from: data) } } @@ -1077,7 +1090,9 @@ public extension Sequence where Element: ParseUser { /** Fetches a collection of users *synchronously* all at once and throws an error if necessary. - + - parameter includeKeys: The name(s) of the key(s) to include that are + `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: Returns a Result enum with the object if a fetch was successful or a `ParseError` if it failed. @@ -1086,12 +1101,16 @@ public extension Sequence where Element: ParseUser { - warning: The order in which users are returned are not guarenteed. You shouldn't expect results in any particular order. */ - func fetchAll(options: API.Options = []) throws -> [(Result)] { + func fetchAll(includeKeys: [String]? = nil, + options: API.Options = []) throws -> [(Result)] { if (allSatisfy { $0.className == Self.Element.className}) { let uniqueObjectIds = Set(self.compactMap { $0.objectId }) - let query = Self.Element.query(containedIn(key: "objectId", array: [uniqueObjectIds])) + var query = Self.Element.query(containedIn(key: "objectId", array: [uniqueObjectIds])) .limit(uniqueObjectIds.count) + if let include = includeKeys { + query = query.include(include) + } let fetchedObjects = try query.find(options: options) var fetchedObjectsToReturn = [(Result)]() @@ -1114,7 +1133,9 @@ public extension Sequence where Element: ParseUser { /** Fetches a collection of users all at once *asynchronously* and executes the completion block when done. - + - parameter includeKeys: The name(s) of the key(s) to include that are + `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - parameter callbackQueue: The queue to return to after completion. Default value of .main. - parameter completion: The block to execute. @@ -1124,13 +1145,17 @@ public extension Sequence where Element: ParseUser { any particular order. */ func fetchAll( + includeKeys: [String]? = nil, options: API.Options = [], callbackQueue: DispatchQueue = .main, completion: @escaping (Result<[(Result)], ParseError>) -> Void ) { if (allSatisfy { $0.className == Self.Element.className}) { let uniqueObjectIds = Set(compactMap { $0.objectId }) - let query = Self.Element.query(containedIn(key: "objectId", array: [uniqueObjectIds])) + var query = Self.Element.query(containedIn(key: "objectId", array: [uniqueObjectIds])) + if let include = includeKeys { + query = query.include(include) + } query.find(options: options, callbackQueue: callbackQueue) { result in switch result { diff --git a/Sources/ParseSwift/Protocols/Fetchable.swift b/Sources/ParseSwift/Protocols/Fetchable.swift index 809239626..869fe1272 100644 --- a/Sources/ParseSwift/Protocols/Fetchable.swift +++ b/Sources/ParseSwift/Protocols/Fetchable.swift @@ -9,12 +9,12 @@ public protocol Fetchable: Decodable { associatedtype FetchingType - func fetch(options: API.Options) throws -> FetchingType + func fetch(includeKeys: [String]?, options: API.Options) throws -> FetchingType func fetch() throws -> FetchingType } extension Fetchable { public func fetch() throws -> FetchingType { - try fetch(options: []) + try fetch(includeKeys: nil, options: []) } } diff --git a/Sources/ParseSwift/Types/ParseFile.swift b/Sources/ParseSwift/Types/ParseFile.swift index 6679eaba0..6a1c69d4f 100644 --- a/Sources/ParseSwift/Types/ParseFile.swift +++ b/Sources/ParseSwift/Types/ParseFile.swift @@ -500,10 +500,11 @@ extension ParseFile { /** Fetches a file with given url *synchronously*. + - parameter includeKeys: Currently not used for `ParseFile`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: A saved `ParseFile`. */ - public func fetch(options: API.Options = []) throws -> ParseFile { + public func fetch(includeKeys: [String]? = nil, options: API.Options = []) throws -> ParseFile { var options = options if let mimeType = mimeType { options.insert(.mimeType(mimeType)) diff --git a/Sources/ParseSwift/Types/Pointer.swift b/Sources/ParseSwift/Types/Pointer.swift index 5186bfe2f..04e658ffa 100644 --- a/Sources/ParseSwift/Types/Pointer.swift +++ b/Sources/ParseSwift/Types/Pointer.swift @@ -43,7 +43,7 @@ public struct Pointer: Fetchable, Encodable { } extension Pointer { - public func fetch(options: API.Options = []) throws -> T { + public func fetch(includeKeys: [String]? = nil, options: API.Options = []) throws -> T { let path = API.Endpoint.object(className: className, objectId: objectId) return try API.NonParseBodyCommand(method: .GET, path: path) { (data) -> T in diff --git a/Tests/ParseSwiftTests/ParseCloudTests.swift b/Tests/ParseSwiftTests/ParseCloudTests.swift index b539d5615..d0e7faa05 100644 --- a/Tests/ParseSwiftTests/ParseCloudTests.swift +++ b/Tests/ParseSwiftTests/ParseCloudTests.swift @@ -27,7 +27,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length override func setUpWithError() throws { try super.setUpWithError() - guard let url = URL(string: "https://localhost:1337/1") else { + guard let url = URL(string: "http://localhost:1337/1") else { XCTFail("Should create valid URL") return } diff --git a/Tests/ParseSwiftTests/ParseConfigTests.swift b/Tests/ParseSwiftTests/ParseConfigTests.swift index d875bd00f..a54e85cc7 100644 --- a/Tests/ParseSwiftTests/ParseConfigTests.swift +++ b/Tests/ParseSwiftTests/ParseConfigTests.swift @@ -66,7 +66,7 @@ class ParseConfigTests: XCTestCase { // swiftlint:disable:this type_body_length override func setUpWithError() throws { try super.setUpWithError() - guard let url = URL(string: "https://localhost:1337/1") else { + guard let url = URL(string: "http://localhost:1337/1") else { XCTFail("Should create valid URL") return } diff --git a/Tests/ParseSwiftTests/ParseInstallationTests.swift b/Tests/ParseSwiftTests/ParseInstallationTests.swift index dbac1044e..c9990341f 100644 --- a/Tests/ParseSwiftTests/ParseInstallationTests.swift +++ b/Tests/ParseSwiftTests/ParseInstallationTests.swift @@ -439,7 +439,7 @@ class ParseInstallationTests: XCTestCase { // swiftlint:disable:this type_body_l let objectId = "yarr" installation.objectId = objectId do { - let command = try installation.fetchCommand() + let command = try installation.fetchCommand(include: nil) XCTAssertNotNil(command) XCTAssertEqual(command.path.urlComponent, "/installations/\(objectId)") XCTAssertEqual(command.method, API.Method.GET) @@ -450,7 +450,39 @@ class ParseInstallationTests: XCTestCase { // swiftlint:disable:this type_body_l } let installation2 = Installation() - XCTAssertThrowsError(try installation2.fetchCommand()) + XCTAssertThrowsError(try installation2.fetchCommand(include: nil)) + } + + func testFetchIncludeCommand() { + var installation = Installation() + let objectId = "yarr" + installation.objectId = objectId + let includeExpected = ["include": "yolo,test"] + do { + let command = try installation.fetchCommand(include: ["yolo", "test"]) + XCTAssertNotNil(command) + XCTAssertEqual(command.path.urlComponent, "/installations/\(objectId)") + XCTAssertEqual(command.method, API.Method.GET) + XCTAssertEqual(command.params, includeExpected) + XCTAssertNil(command.body) + + guard let urlExpected = URL(string: "http://localhost:1337/1/installations/yarr?include=yolo,test") else { + XCTFail("Should have unwrapped") + return + } + let request = command.prepareURLRequest(options: []) + switch request { + case .success(let url): + XCTAssertEqual(url.url, urlExpected) + case .failure(let error): + XCTFail(error.localizedDescription) + } + } catch { + XCTFail(error.localizedDescription) + } + + let installation2 = Installation() + XCTAssertThrowsError(try installation2.fetchCommand(include: nil)) } func testFetchUpdatedCurrentInstallation() { // swiftlint:disable:this function_body_length diff --git a/Tests/ParseSwiftTests/ParseObjectBatchTests.swift b/Tests/ParseSwiftTests/ParseObjectBatchTests.swift index 15289aed8..f7a64dc6a 100644 --- a/Tests/ParseSwiftTests/ParseObjectBatchTests.swift +++ b/Tests/ParseSwiftTests/ParseObjectBatchTests.swift @@ -34,7 +34,7 @@ class ParseObjectBatchTests: XCTestCase { // swiftlint:disable:this type_body_le override func setUp() { super.setUp() - guard let url = URL(string: "https://localhost:1337/1") else { + guard let url = URL(string: "http://localhost:1337/1") else { XCTFail("Should create valid URL") return } diff --git a/Tests/ParseSwiftTests/ParseObjectTests.swift b/Tests/ParseSwiftTests/ParseObjectTests.swift index 5665a9e21..f5a8661ae 100644 --- a/Tests/ParseSwiftTests/ParseObjectTests.swift +++ b/Tests/ParseSwiftTests/ParseObjectTests.swift @@ -188,7 +188,7 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length override func setUp() { super.setUp() - guard let url = URL(string: "https://localhost:1337/1") else { + guard let url = URL(string: "http://localhost:1337/1") else { XCTFail("Should create valid URL") return } @@ -227,7 +227,7 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length let objectId = "yarr" score.objectId = objectId do { - let command = try score.fetchCommand() + let command = try score.fetchCommand(include: nil) XCTAssertNotNil(command) XCTAssertEqual(command.path.urlComponent, "/classes/\(className)/\(objectId)") XCTAssertEqual(command.method, API.Method.GET) @@ -239,6 +239,38 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length } } + func testFetchIncludeCommand() { + var score = GameScore(score: 10) + let className = score.className + let objectId = "yarr" + score.objectId = objectId + let includeExpected = ["include": "yolo,test"] + do { + let command = try score.fetchCommand(include: ["yolo", "test"]) + XCTAssertNotNil(command) + XCTAssertEqual(command.path.urlComponent, "/classes/\(className)/\(objectId)") + XCTAssertEqual(command.method, API.Method.GET) + XCTAssertEqual(command.params, includeExpected) + XCTAssertNil(command.body) + XCTAssertNil(command.data) + + // swiftlint:disable:next line_length + guard let urlExpected = URL(string: "http://localhost:1337/1/classes/GameScore/yarr?include=yolo,test") else { + XCTFail("Should have unwrapped") + return + } + let request = command.prepareURLRequest(options: []) + switch request { + case .success(let url): + XCTAssertEqual(url.url, urlExpected) + case .failure(let error): + XCTFail(error.localizedDescription) + } + } catch { + XCTFail(error.localizedDescription) + } + } + // swiftlint:disable:next function_body_length func testFetch() { var score = GameScore(score: 10) diff --git a/Tests/ParseSwiftTests/ParsePointerTests.swift b/Tests/ParseSwiftTests/ParsePointerTests.swift index 1e059464c..c9a64512a 100644 --- a/Tests/ParseSwiftTests/ParsePointerTests.swift +++ b/Tests/ParseSwiftTests/ParsePointerTests.swift @@ -31,7 +31,7 @@ class ParsePointerTests: XCTestCase { override func setUpWithError() throws { try super.setUpWithError() - guard let url = URL(string: "https://localhost:1337/1") else { + guard let url = URL(string: "http://localhost:1337/1") else { throw ParseError(code: .unknownError, message: "Should create valid URL") } ParseSwift.initialize(applicationId: "applicationId", diff --git a/Tests/ParseSwiftTests/ParseSessionTests.swift b/Tests/ParseSwiftTests/ParseSessionTests.swift index d98913dd0..cb378c197 100644 --- a/Tests/ParseSwiftTests/ParseSessionTests.swift +++ b/Tests/ParseSwiftTests/ParseSessionTests.swift @@ -79,7 +79,7 @@ class ParseSessionTests: XCTestCase { var session = Session() session.objectId = "me" do { - let command = try session.fetchCommand() + let command = try session.fetchCommand(include: nil) XCTAssertNotNil(command) //Generates this component because fetchCommand is at the Objective protocol level XCTAssertEqual(command.path.urlComponent, "/classes/_Session/me") diff --git a/Tests/ParseSwiftTests/ParseUserTests.swift b/Tests/ParseSwiftTests/ParseUserTests.swift index 230bf52b7..b5882890b 100644 --- a/Tests/ParseSwiftTests/ParseUserTests.swift +++ b/Tests/ParseSwiftTests/ParseUserTests.swift @@ -89,7 +89,7 @@ class ParseUserTests: XCTestCase { // swiftlint:disable:this type_body_length let objectId = "yarr" user.objectId = objectId do { - let command = try user.fetchCommand() + let command = try user.fetchCommand(include: nil) XCTAssertNotNil(command) XCTAssertEqual(command.path.urlComponent, "/users/\(objectId)") XCTAssertEqual(command.method, API.Method.GET) @@ -101,7 +101,40 @@ class ParseUserTests: XCTestCase { // swiftlint:disable:this type_body_length } let user2 = User() - XCTAssertThrowsError(try user2.fetchCommand()) + XCTAssertThrowsError(try user2.fetchCommand(include: nil)) + } + + func testFetchIncludeCommand() { + var user = User() + let objectId = "yarr" + user.objectId = objectId + let includeExpected = ["include": "yolo,test"] + do { + let command = try user.fetchCommand(include: ["yolo", "test"]) + XCTAssertNotNil(command) + XCTAssertEqual(command.path.urlComponent, "/users/\(objectId)") + XCTAssertEqual(command.method, API.Method.GET) + XCTAssertEqual(command.params, includeExpected) + XCTAssertNil(command.body) + XCTAssertNil(command.data) + + guard let urlExpected = URL(string: "http://localhost:1337/1/users/yarr?include=yolo,test") else { + XCTFail("Should have unwrapped") + return + } + let request = command.prepareURLRequest(options: []) + switch request { + case .success(let url): + XCTAssertEqual(url.url, urlExpected) + case .failure(let error): + XCTFail(error.localizedDescription) + } + } catch { + XCTFail(error.localizedDescription) + } + + let user2 = User() + XCTAssertThrowsError(try user2.fetchCommand(include: nil)) } func testFetch() { // swiftlint:disable:this function_body_length From 606e6d653bec3a0976d1bd745c6b0e9ef5cc8d18 Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Mon, 1 Feb 2021 19:15:50 -0500 Subject: [PATCH 2/8] Working --- .../Contents.swift | 25 +------------------ Sources/ParseSwift/API/API+Commands.swift | 1 - Sources/ParseSwift/Objects/ParseObject.swift | 2 +- Sources/ParseSwift/Types/ParseCloud.swift | 2 +- 4 files changed, 3 insertions(+), 27 deletions(-) diff --git a/ParseSwift.playground/Pages/6 - Installation.xcplaygroundpage/Contents.swift b/ParseSwift.playground/Pages/6 - Installation.xcplaygroundpage/Contents.swift index 797434ea6..ebd8157bb 100644 --- a/ParseSwift.playground/Pages/6 - Installation.xcplaygroundpage/Contents.swift +++ b/ParseSwift.playground/Pages/6 - Installation.xcplaygroundpage/Contents.swift @@ -71,30 +71,7 @@ DispatchQueue.main.async { case .success(let updatedInstallation): print("Successfully save myCustomInstallationKey to ParseServer: \(updatedInstallation)") case .failure(let error): - assertionFailure("Failed to update installation: \(error)") - } - } - - //: Looking at the output of user from the previous login, it only has - //: a pointer to the `score`and `targetScore` fields. You can fetch using `include` to - //: get the score. - Installation.current?.fetch(includeKeys: ["score"]) { result in - switch result { - case .success(let fetched): - print("Successfully fetched user with score key: \(fetched)") - case .failure(let error): - print("Error fetching score: \(error)") - } - } - - //: The `target` score is still missing. You can get all pointer fields at - //: once by including `["*"]`. - Installation.current?.fetch(includeKeys: ["*"]) { result in - switch result { - case .success(let fetched): - print("Successfully fetched user with all keys: \(fetched)") - case .failure(let error): - print("Error fetching score: \(error)") + print("Failed to update installation: \(error)") } } } diff --git a/Sources/ParseSwift/API/API+Commands.swift b/Sources/ParseSwift/API/API+Commands.swift index e7597f186..f6dc436af 100644 --- a/Sources/ParseSwift/API/API+Commands.swift +++ b/Sources/ParseSwift/API/API+Commands.swift @@ -240,7 +240,6 @@ internal extension API { } } urlRequest.httpMethod = method.rawValue - print(urlRequest) return .success(urlRequest) } diff --git a/Sources/ParseSwift/Objects/ParseObject.swift b/Sources/ParseSwift/Objects/ParseObject.swift index 211362499..384406a6b 100644 --- a/Sources/ParseSwift/Objects/ParseObject.swift +++ b/Sources/ParseSwift/Objects/ParseObject.swift @@ -444,7 +444,7 @@ public extension Sequence where Element: ParseObject { // MARK: CustomDebugStringConvertible extension ParseObject { public var debugDescription: String { - guard let descriptionData = try? ParseCoding.parseEncoder().encode(self, skipKeys: .none), + guard let descriptionData = try? ParseCoding.jsonEncoder().encode(self), let descriptionString = String(data: descriptionData, encoding: .utf8) else { return "\(className) ()" } diff --git a/Sources/ParseSwift/Types/ParseCloud.swift b/Sources/ParseSwift/Types/ParseCloud.swift index 893640f9e..65b436d01 100644 --- a/Sources/ParseSwift/Types/ParseCloud.swift +++ b/Sources/ParseSwift/Types/ParseCloud.swift @@ -117,7 +117,7 @@ extension ParseCloud { // MARK: CustomDebugStringConvertible extension ParseCloud { public var debugDescription: String { - guard let descriptionData = try? ParseCoding.parseEncoder().encode(self, skipKeys: .none), + guard let descriptionData = try? ParseCoding.jsonEncoder().encode(self), let descriptionString = String(data: descriptionData, encoding: .utf8) else { return "\(functionJobName)" } From 27340cf5d6ca22e5aff961cdbf5e736a0290242d Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Mon, 1 Feb 2021 19:22:08 -0500 Subject: [PATCH 3/8] Switch all debug statements to jsonEncoder --- Sources/ParseSwift/Types/ParseConfig.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/ParseSwift/Types/ParseConfig.swift b/Sources/ParseSwift/Types/ParseConfig.swift index 956500564..2864b3d5f 100644 --- a/Sources/ParseSwift/Types/ParseConfig.swift +++ b/Sources/ParseSwift/Types/ParseConfig.swift @@ -184,7 +184,7 @@ extension ParseConfig { // MARK: CustomDebugStringConvertible extension ParseConfig { public var debugDescription: String { - guard let descriptionData = try? ParseCoding.parseEncoder().encode(self, skipKeys: .none), + guard let descriptionData = try? ParseCoding.jsonEncoder().encode(self), let descriptionString = String(data: descriptionData, encoding: .utf8) else { return "" } From 223757bcf7a380b20a9de4f2bb081f2c353d9b6b Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Mon, 1 Feb 2021 19:33:23 -0500 Subject: [PATCH 4/8] nits --- .../Contents.swift | 2 +- .../Contents.swift | 25 ------------------- 2 files changed, 1 insertion(+), 26 deletions(-) diff --git a/ParseSwift.playground/Pages/4 - User - Continued.xcplaygroundpage/Contents.swift b/ParseSwift.playground/Pages/4 - User - Continued.xcplaygroundpage/Contents.swift index 5136ddb4c..422af3be6 100644 --- a/ParseSwift.playground/Pages/4 - User - Continued.xcplaygroundpage/Contents.swift +++ b/ParseSwift.playground/Pages/4 - User - Continued.xcplaygroundpage/Contents.swift @@ -59,7 +59,7 @@ User.current?.save { results in switch results { case .success(let updatedUser): - print("Successfully save myCustomKey and score to ParseServer: \(updatedUser)") + print("Successfully save custom fields of User to ParseServer: \(updatedUser)") case .failure(let error): print("Failed to update user: \(error)") } diff --git a/ParseSwift.playground/Pages/6 - Installation.xcplaygroundpage/Contents.swift b/ParseSwift.playground/Pages/6 - Installation.xcplaygroundpage/Contents.swift index ebd8157bb..a50403a1d 100644 --- a/ParseSwift.playground/Pages/6 - Installation.xcplaygroundpage/Contents.swift +++ b/ParseSwift.playground/Pages/6 - Installation.xcplaygroundpage/Contents.swift @@ -29,29 +29,6 @@ struct Installation: ParseInstallation { //: Your custom keys var customKey: String? - var score: GameScore? - var targetScore: GameScore? -} - -//: Create your own value typed `ParseObject`. -struct GameScore: ParseObject { - //: Those are required for Object - var objectId: String? - var createdAt: Date? - var updatedAt: Date? - var ACL: ParseACL? - - //: Your own properties. - var score: Int? = 0 - - //: Custom initializer. - init(score: Int) { - self.score = score - } - - init(objectId: String?) { - self.objectId = objectId - } } //: WARNING: All calls on Installation need to be done on the main queue @@ -63,8 +40,6 @@ DispatchQueue.main.async { returns to main queue. */ Installation.current?.customKey = "myCustomInstallationKey2" - Installation.current?.score = GameScore(score: 12) - Installation.current?.targetScore = GameScore(score: 100) Installation.current?.save { results in switch results { From 476cfa081ef52be5869adfd455ab9d133a13adc1 Mon Sep 17 00:00:00 2001 From: Corey Date: Mon, 1 Feb 2021 19:50:25 -0500 Subject: [PATCH 5/8] Update Sources/ParseSwift/Objects/ParseInstallation+combine.swift Co-authored-by: Tom Fox <13188249+TomWFox@users.noreply.github.com> --- Sources/ParseSwift/Objects/ParseInstallation+combine.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/ParseSwift/Objects/ParseInstallation+combine.swift b/Sources/ParseSwift/Objects/ParseInstallation+combine.swift index 1025562e3..1c0103dbd 100644 --- a/Sources/ParseSwift/Objects/ParseInstallation+combine.swift +++ b/Sources/ParseSwift/Objects/ParseInstallation+combine.swift @@ -19,7 +19,7 @@ public extension ParseInstallation { Fetches the `ParseInstallation` *aynchronously* with the current data from the server and sets an error if one occurs. Publishes when complete. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: A publisher that eventually produces a single value and then finishes or fails. From 0ece83ffdcb6a8545809535e74ee6b26e8dbd587 Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Mon, 1 Feb 2021 19:52:56 -0500 Subject: [PATCH 6/8] nits --- .../Contents.swift | 2 +- .../Pages/13 - Operations.xcplaygroundpage/Contents.swift | 2 +- .../ParseSwift/Objects/ParseInstallation+combine.swift | 2 +- Sources/ParseSwift/Objects/ParseInstallation.swift | 8 ++++---- Sources/ParseSwift/Objects/ParseObject+combine.swift | 4 ++-- Sources/ParseSwift/Objects/ParseObject.swift | 6 +++--- Sources/ParseSwift/Objects/ParseUser+combine.swift | 4 ++-- Sources/ParseSwift/Objects/ParseUser.swift | 8 ++++---- Tests/ParseSwiftTests/ParseObjectTests.swift | 8 ++++---- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/ParseSwift.playground/Pages/12 - Roles and Relations.xcplaygroundpage/Contents.swift b/ParseSwift.playground/Pages/12 - Roles and Relations.xcplaygroundpage/Contents.swift index e7191192d..43eac5f0c 100644 --- a/ParseSwift.playground/Pages/12 - Roles and Relations.xcplaygroundpage/Contents.swift +++ b/ParseSwift.playground/Pages/12 - Roles and Relations.xcplaygroundpage/Contents.swift @@ -211,7 +211,7 @@ do { print(error) } -//: All `ParseObjects` have a `ParseRelation` attribute that be used on instances. +//: All `ParseObject`s have a `ParseRelation` attribute that be used on instances. //: For example, the User has: let relation = User.current!.relation diff --git a/ParseSwift.playground/Pages/13 - Operations.xcplaygroundpage/Contents.swift b/ParseSwift.playground/Pages/13 - Operations.xcplaygroundpage/Contents.swift index 6dc569e34..f0fd4c544 100644 --- a/ParseSwift.playground/Pages/13 - Operations.xcplaygroundpage/Contents.swift +++ b/ParseSwift.playground/Pages/13 - Operations.xcplaygroundpage/Contents.swift @@ -59,7 +59,7 @@ do { print(error) } -//: There are other operations: add/remove/delete objects from `ParseObjects`. +//: There are other operations: add/remove/delete objects from `ParseObject`s. //: In fact, the `users` and `roles` relations from `ParseRoles` used the add/remove operations. let operations = savedScore.operation diff --git a/Sources/ParseSwift/Objects/ParseInstallation+combine.swift b/Sources/ParseSwift/Objects/ParseInstallation+combine.swift index 1c0103dbd..1493f8c88 100644 --- a/Sources/ParseSwift/Objects/ParseInstallation+combine.swift +++ b/Sources/ParseSwift/Objects/ParseInstallation+combine.swift @@ -71,7 +71,7 @@ public extension Sequence where Element: ParseInstallation { Fetches a collection of installations *aynchronously* with the current data from the server and sets an error if one occurs. Publishes when complete. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: A publisher that eventually produces a single value and then finishes or fails. diff --git a/Sources/ParseSwift/Objects/ParseInstallation.swift b/Sources/ParseSwift/Objects/ParseInstallation.swift index 71a1d069e..69dc9fe71 100644 --- a/Sources/ParseSwift/Objects/ParseInstallation.swift +++ b/Sources/ParseSwift/Objects/ParseInstallation.swift @@ -339,7 +339,7 @@ extension ParseInstallation { Fetches the `ParseInstallation` *synchronously* with the current data from the server and sets an error if one occurs. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - throws: An error of `ParseError` type. @@ -356,7 +356,7 @@ extension ParseInstallation { /** Fetches the `ParseInstallation` *asynchronously* and executes the given callback block. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - parameter callbackQueue: The queue to return to after completion. Default @@ -770,7 +770,7 @@ public extension Sequence where Element: ParseInstallation { /** Fetches a collection of installations *synchronously* all at once and throws an error if necessary. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. @@ -815,7 +815,7 @@ public extension Sequence where Element: ParseInstallation { /** Fetches a collection of installations all at once *asynchronously* and executes the completion block when done. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - parameter callbackQueue: The queue to return to after completion. Default value of .main. diff --git a/Sources/ParseSwift/Objects/ParseObject+combine.swift b/Sources/ParseSwift/Objects/ParseObject+combine.swift index f75bfa567..918f4455c 100644 --- a/Sources/ParseSwift/Objects/ParseObject+combine.swift +++ b/Sources/ParseSwift/Objects/ParseObject+combine.swift @@ -18,7 +18,7 @@ public extension ParseObject { Fetches the `ParseObject` *aynchronously* with the current data from the server and sets an error if one occurs. Publishes when complete. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: A publisher that eventually produces a single value and then finishes or fails. @@ -68,7 +68,7 @@ public extension Sequence where Element: ParseObject { Fetches a collection of objects *aynchronously* with the current data from the server and sets an error if one occurs. Publishes when complete. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: A publisher that eventually produces a single value and then finishes or fails. diff --git a/Sources/ParseSwift/Objects/ParseObject.swift b/Sources/ParseSwift/Objects/ParseObject.swift index 384406a6b..aad1e618c 100644 --- a/Sources/ParseSwift/Objects/ParseObject.swift +++ b/Sources/ParseSwift/Objects/ParseObject.swift @@ -230,7 +230,7 @@ public extension Sequence where Element: ParseObject { /** Fetches a collection of objects *synchronously* all at once and throws an error if necessary. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. @@ -271,7 +271,7 @@ public extension Sequence where Element: ParseObject { /** Fetches a collection of objects all at once *asynchronously* and executes the completion block when done. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - parameter callbackQueue: The queue to return to after completion. Default value of .main. @@ -459,7 +459,7 @@ extension ParseObject { /** Fetches the `ParseObject` *synchronously* with the current data from the server and sets an error if one occurs. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - throws: An error of `ParseError` type. diff --git a/Sources/ParseSwift/Objects/ParseUser+combine.swift b/Sources/ParseSwift/Objects/ParseUser+combine.swift index 2f5b2d06b..619ff287b 100644 --- a/Sources/ParseSwift/Objects/ParseUser+combine.swift +++ b/Sources/ParseSwift/Objects/ParseUser+combine.swift @@ -141,7 +141,7 @@ public extension ParseUser { Fetches the `ParseUser` *aynchronously* with the current data from the server and sets an error if one occurs. Publishes when complete. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: A publisher that eventually produces a single value and then finishes or fails. @@ -193,7 +193,7 @@ public extension Sequence where Element: ParseUser { Fetches a collection of users *aynchronously* with the current data from the server and sets an error if one occurs. Publishes when complete. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: A publisher that eventually produces a single value and then finishes or fails. diff --git a/Sources/ParseSwift/Objects/ParseUser.swift b/Sources/ParseSwift/Objects/ParseUser.swift index 5c10be4c5..2d394d3f2 100644 --- a/Sources/ParseSwift/Objects/ParseUser.swift +++ b/Sources/ParseSwift/Objects/ParseUser.swift @@ -648,7 +648,7 @@ extension ParseUser { /** Fetches the `ParseUser` *synchronously* with the current data from the server and sets an error if one occurs. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - throws: An error of `ParseError` type. @@ -666,7 +666,7 @@ extension ParseUser { /** Fetches the `ParseUser` *asynchronously* and executes the given callback block. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - parameter callbackQueue: The queue to return to after completion. Default @@ -1091,7 +1091,7 @@ public extension Sequence where Element: ParseUser { /** Fetches a collection of users *synchronously* all at once and throws an error if necessary. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. @@ -1134,7 +1134,7 @@ public extension Sequence where Element: ParseUser { /** Fetches a collection of users all at once *asynchronously* and executes the completion block when done. - parameter includeKeys: The name(s) of the key(s) to include that are - `ParseObjects`. Use `["*"]` to include all keys. This is similar to `include` and + `ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and `includeAll` for `Query`. - parameter options: A set of header options sent to the server. Defaults to an empty set. - parameter callbackQueue: The queue to return to after completion. Default value of .main. diff --git a/Tests/ParseSwiftTests/ParseObjectTests.swift b/Tests/ParseSwiftTests/ParseObjectTests.swift index f5a8661ae..ff77fe939 100644 --- a/Tests/ParseSwiftTests/ParseObjectTests.swift +++ b/Tests/ParseSwiftTests/ParseObjectTests.swift @@ -108,7 +108,7 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length has been previously synced to the parse-server (has an objectId). In addition, if two `ParseObject`'s have the same objectId, but were modified at different times, the default implementation will still return true. In these cases you either want to use a - "struct" (value types) to make your `ParseObjects` instead of a class (reference type) or + "struct" (value types) to make your `ParseObject`s instead of a class (reference type) or provide your own implementation of `==`. - parameter lhs: first object to compare - parameter rhs: second object to compare @@ -126,7 +126,7 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length - warning: If you use the default implementation, hash will only work if the ParseObject has been previously synced to the parse-server (has an objectId). In addition, if two `ParseObject`'s have the same objectId, but were modified at different times, the default implementation will hash to the same value. In these - cases you either want to use a "struct" (value types) to make your `ParseObjects` instead of a + cases you either want to use a "struct" (value types) to make your `ParseObject`s instead of a class (reference type) or provide your own implementation of `hash`. */ @@ -160,7 +160,7 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length has been previously synced to the parse-server (has an objectId). In addition, if two `ParseObject`'s have the same objectId, but were modified at different times, the default implementation will still return true. In these cases you either want to use a - "struct" (value types) to make your `ParseObjects` instead of a class (reference type) or + "struct" (value types) to make your `ParseObject`s instead of a class (reference type) or provide your own implementation of `==`. - parameter lhs: first object to compare - parameter rhs: second object to compare @@ -177,7 +177,7 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length - warning: If you use the default implementation, hash will only work if the ParseObject has been previously synced to the parse-server (has an objectId). In addition, if two `ParseObject`'s have the same objectId, but were modified at different times, the default implementation will hash to the same value. In these - cases you either want to use a "struct" (value types) to make your `ParseObjects` instead of a + cases you either want to use a "struct" (value types) to make your `ParseObject`s instead of a class (reference type) or provide your own implementation of `hash`. */ From a5c1daf69d94e21bd89fc61951722604201fc068 Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Mon, 1 Feb 2021 20:23:05 -0500 Subject: [PATCH 7/8] Fix date issues causing random failures --- Tests/ParseSwiftTests/ParseACLTests.swift | 5 ++-- .../ParseSwiftTests/ParseAnonymousTests.swift | 5 ++-- .../ParseAppleCombineTests.swift | 5 ++-- Tests/ParseSwiftTests/ParseAppleTests.swift | 5 ++-- .../ParseConfigCombineTests.swift | 5 ++-- Tests/ParseSwiftTests/ParseConfigTests.swift | 5 ++-- Tests/ParseSwiftTests/ParseEncoderTests.swift | 2 +- .../ParseInstallationCombineTests.swift | 5 ++-- .../ParseInstallationTests.swift | 5 ++-- .../ParseObjectBatchTests.swift | 4 ++-- Tests/ParseSwiftTests/ParseObjectTests.swift | 24 +++++++++---------- Tests/ParseSwiftTests/ParsePointerTests.swift | 6 ++--- .../ParseQueryCombineTests.swift | 8 +++---- Tests/ParseSwiftTests/ParseQueryTests.swift | 24 +++++++++---------- .../ParseUserCombineTests.swift | 5 ++-- Tests/ParseSwiftTests/ParseUserTests.swift | 7 +++--- 16 files changed, 65 insertions(+), 55 deletions(-) diff --git a/Tests/ParseSwiftTests/ParseACLTests.swift b/Tests/ParseSwiftTests/ParseACLTests.swift index 29606c825..ea9de1eb1 100644 --- a/Tests/ParseSwiftTests/ParseACLTests.swift +++ b/Tests/ParseSwiftTests/ParseACLTests.swift @@ -68,8 +68,9 @@ class ParseACLTests: XCTestCase { var customKey: String? init() { - self.createdAt = Date() - self.updatedAt = Date() + let date = Date() + self.createdAt = date + self.updatedAt = date self.objectId = "yarr" self.ACL = nil self.customKey = "blah" diff --git a/Tests/ParseSwiftTests/ParseAnonymousTests.swift b/Tests/ParseSwiftTests/ParseAnonymousTests.swift index 3a3a6d3f0..a194f8df5 100644 --- a/Tests/ParseSwiftTests/ParseAnonymousTests.swift +++ b/Tests/ParseSwiftTests/ParseAnonymousTests.swift @@ -45,8 +45,9 @@ class ParseAnonymousTests: XCTestCase { var customKey: String? init() { - self.createdAt = Date() - self.updatedAt = Date() + let date = Date() + self.createdAt = date + self.updatedAt = date self.objectId = "yarr" self.ACL = nil self.customKey = "blah" diff --git a/Tests/ParseSwiftTests/ParseAppleCombineTests.swift b/Tests/ParseSwiftTests/ParseAppleCombineTests.swift index feebc740c..0fd30ec41 100644 --- a/Tests/ParseSwiftTests/ParseAppleCombineTests.swift +++ b/Tests/ParseSwiftTests/ParseAppleCombineTests.swift @@ -49,8 +49,9 @@ class ParseAppleCombineTests: XCTestCase { // swiftlint:disable:this type_body_l var customKey: String? init() { - self.createdAt = Date() - self.updatedAt = Date() + let date = Date() + self.createdAt = date + self.updatedAt = date self.objectId = "yarr" self.ACL = nil self.customKey = "blah" diff --git a/Tests/ParseSwiftTests/ParseAppleTests.swift b/Tests/ParseSwiftTests/ParseAppleTests.swift index a068846c0..81f7ec52b 100644 --- a/Tests/ParseSwiftTests/ParseAppleTests.swift +++ b/Tests/ParseSwiftTests/ParseAppleTests.swift @@ -44,8 +44,9 @@ class ParseAppleTests: XCTestCase { var customKey: String? init() { - self.createdAt = Date() - self.updatedAt = Date() + let date = Date() + self.createdAt = date + self.updatedAt = date self.objectId = "yarr" self.ACL = nil self.customKey = "blah" diff --git a/Tests/ParseSwiftTests/ParseConfigCombineTests.swift b/Tests/ParseSwiftTests/ParseConfigCombineTests.swift index 7b2eea0e9..5d471cb30 100644 --- a/Tests/ParseSwiftTests/ParseConfigCombineTests.swift +++ b/Tests/ParseSwiftTests/ParseConfigCombineTests.swift @@ -57,8 +57,9 @@ class ParseConfigCombineTests: XCTestCase { // swiftlint:disable:this type_body_ var customKey: String? init() { - self.createdAt = Date() - self.updatedAt = Date() + let date = Date() + self.createdAt = date + self.updatedAt = date self.objectId = "yarr" self.ACL = nil self.customKey = "blah" diff --git a/Tests/ParseSwiftTests/ParseConfigTests.swift b/Tests/ParseSwiftTests/ParseConfigTests.swift index a54e85cc7..0ac54ee80 100644 --- a/Tests/ParseSwiftTests/ParseConfigTests.swift +++ b/Tests/ParseSwiftTests/ParseConfigTests.swift @@ -53,8 +53,9 @@ class ParseConfigTests: XCTestCase { // swiftlint:disable:this type_body_length var customKey: String? init() { - self.createdAt = Date() - self.updatedAt = Date() + let date = Date() + self.createdAt = date + self.updatedAt = date self.objectId = "yarr" self.ACL = nil self.customKey = "blah" diff --git a/Tests/ParseSwiftTests/ParseEncoderTests.swift b/Tests/ParseSwiftTests/ParseEncoderTests.swift index 28d45b636..5cce56ea8 100644 --- a/Tests/ParseSwiftTests/ParseEncoderTests.swift +++ b/Tests/ParseSwiftTests/ParseEncoderTests.swift @@ -76,7 +76,7 @@ class ParseEncoderTests: XCTestCase { var score = GameScore(score: 10) score.objectId = "yarr" score.createdAt = Date() - score.updatedAt = Date() + score.updatedAt = score.createdAt let encodedJSON = try ParseCoding.jsonEncoder().encode(score) let decodedJSON = try ParseCoding.jsonDecoder().decode([String: AnyCodable].self, from: encodedJSON) diff --git a/Tests/ParseSwiftTests/ParseInstallationCombineTests.swift b/Tests/ParseSwiftTests/ParseInstallationCombineTests.swift index 01655f78a..3f0d87b0b 100644 --- a/Tests/ParseSwiftTests/ParseInstallationCombineTests.swift +++ b/Tests/ParseSwiftTests/ParseInstallationCombineTests.swift @@ -52,8 +52,9 @@ class ParseInstallationCombineTests: XCTestCase { // swiftlint:disable:this type var customKey: String? init() { - self.createdAt = Date() - self.updatedAt = Date() + let date = Date() + self.createdAt = date + self.updatedAt = date self.objectId = "yarr" self.ACL = nil self.customKey = "blah" diff --git a/Tests/ParseSwiftTests/ParseInstallationTests.swift b/Tests/ParseSwiftTests/ParseInstallationTests.swift index c9990341f..acffa8617 100644 --- a/Tests/ParseSwiftTests/ParseInstallationTests.swift +++ b/Tests/ParseSwiftTests/ParseInstallationTests.swift @@ -53,8 +53,9 @@ class ParseInstallationTests: XCTestCase { // swiftlint:disable:this type_body_l var customKey: String? init() { - self.createdAt = Date() - self.updatedAt = Date() + let date = Date() + self.createdAt = date + self.updatedAt = date self.objectId = "yarr" self.ACL = nil self.customKey = "blah" diff --git a/Tests/ParseSwiftTests/ParseObjectBatchTests.swift b/Tests/ParseSwiftTests/ParseObjectBatchTests.swift index f7a64dc6a..8c0ac8347 100644 --- a/Tests/ParseSwiftTests/ParseObjectBatchTests.swift +++ b/Tests/ParseSwiftTests/ParseObjectBatchTests.swift @@ -272,10 +272,10 @@ class ParseObjectBatchTests: XCTestCase { // swiftlint:disable:this type_body_le score.objectId = "yarr" score.createdAt = Date() - score.updatedAt = Date() + score.updatedAt = score.createdAt score2.objectId = "yolo" score2.createdAt = Date() - score2.updatedAt = Date() + score2.updatedAt = score2.createdAt let objects = [score, score2] let initialCommands = objects.map { $0.saveCommand() } diff --git a/Tests/ParseSwiftTests/ParseObjectTests.swift b/Tests/ParseSwiftTests/ParseObjectTests.swift index ff77fe939..2e7e4689e 100644 --- a/Tests/ParseSwiftTests/ParseObjectTests.swift +++ b/Tests/ParseSwiftTests/ParseObjectTests.swift @@ -342,7 +342,7 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length var scoreOnServer = score scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil let encoded: Data! do { @@ -448,7 +448,7 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length var scoreOnServer = score scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil let encoded: Data! @@ -477,7 +477,7 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length var scoreOnServer = score scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil let encoded: Data! do { @@ -526,7 +526,7 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length let objectId = "yarr" score.objectId = objectId score.createdAt = Date() - score.updatedAt = Date() + score.updatedAt = score.createdAt let command = score.saveCommand() XCTAssertNotNil(command) @@ -907,7 +907,7 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length var scoreOnServer = score scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil let encoded: Data! do { @@ -1005,7 +1005,7 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length var scoreOnServer = score scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil let encoded: Data! @@ -1034,7 +1034,7 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length var scoreOnServer = score scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil let encoded: Data! do { @@ -1105,7 +1105,7 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length var scoreOnServer = score scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil scoreOnServer.objectId = "yarr" let encoded: Data! @@ -1160,7 +1160,7 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length var gameOnServer = game gameOnServer.objectId = "nice" gameOnServer.createdAt = Date() - gameOnServer.updatedAt = Date() + gameOnServer.updatedAt = gameOnServer.createdAt let encodedGamed: Data do { @@ -1217,7 +1217,7 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length var levelOnServer = score levelOnServer.createdAt = Date() - levelOnServer.updatedAt = Date() + levelOnServer.updatedAt = levelOnServer.updatedAt levelOnServer.ACL = nil levelOnServer.objectId = "yarr" let pointer = try levelOnServer.toPointer() @@ -1270,7 +1270,7 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length var scoreOnServer = score scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil scoreOnServer.objectId = "yarr" let encoded: Data! @@ -1369,7 +1369,7 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length var gameOnServer = game gameOnServer.objectId = "nice" gameOnServer.createdAt = Date() - gameOnServer.updatedAt = Date() + gameOnServer.updatedAt = gameOnServer.updatedAt gameOnServer.profilePicture = savedFile let encodedGamed: Data diff --git a/Tests/ParseSwiftTests/ParsePointerTests.swift b/Tests/ParseSwiftTests/ParsePointerTests.swift index c9a64512a..4d93b6713 100644 --- a/Tests/ParseSwiftTests/ParsePointerTests.swift +++ b/Tests/ParseSwiftTests/ParsePointerTests.swift @@ -70,7 +70,7 @@ class ParsePointerTests: XCTestCase { var scoreOnServer = score scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil let encoded: Data! do { @@ -193,7 +193,7 @@ class ParsePointerTests: XCTestCase { var scoreOnServer = score scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.updatedAt scoreOnServer.ACL = nil let encoded: Data! @@ -223,7 +223,7 @@ class ParsePointerTests: XCTestCase { var scoreOnServer = score scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.updatedAt scoreOnServer.ACL = nil let encoded: Data! do { diff --git a/Tests/ParseSwiftTests/ParseQueryCombineTests.swift b/Tests/ParseSwiftTests/ParseQueryCombineTests.swift index f176fc76a..bed7a5df4 100644 --- a/Tests/ParseSwiftTests/ParseQueryCombineTests.swift +++ b/Tests/ParseSwiftTests/ParseQueryCombineTests.swift @@ -71,7 +71,7 @@ class ParseQueryCombineTests: XCTestCase { // swiftlint:disable:this type_body_l scoreOnServer.score = 11 scoreOnServer.objectId = "yolo" scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil let results = QueryResponse(results: [scoreOnServer], count: 1) @@ -157,7 +157,7 @@ class ParseQueryCombineTests: XCTestCase { // swiftlint:disable:this type_body_l scoreOnServer.score = 11 scoreOnServer.objectId = "yolo" scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil let results = QueryResponse(results: [scoreOnServer], count: 1) @@ -239,7 +239,7 @@ class ParseQueryCombineTests: XCTestCase { // swiftlint:disable:this type_body_l scoreOnServer.score = 11 scoreOnServer.objectId = "yolo" scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil let results = QueryResponse(results: [scoreOnServer], count: 1) @@ -320,7 +320,7 @@ class ParseQueryCombineTests: XCTestCase { // swiftlint:disable:this type_body_l var scoreOnServer = GameScore(score: 10) scoreOnServer.objectId = "yarr" scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil let results = QueryResponse(results: [scoreOnServer], count: 1) diff --git a/Tests/ParseSwiftTests/ParseQueryTests.swift b/Tests/ParseSwiftTests/ParseQueryTests.swift index 7b0eecde2..8d10df505 100644 --- a/Tests/ParseSwiftTests/ParseQueryTests.swift +++ b/Tests/ParseSwiftTests/ParseQueryTests.swift @@ -197,7 +197,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length var scoreOnServer = GameScore(score: 10) scoreOnServer.objectId = "yarr" scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil let results = QueryResponse(results: [scoreOnServer], count: 1) @@ -290,7 +290,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length var scoreOnServer = GameScore(score: 10) scoreOnServer.objectId = "yarr" scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil let results = QueryResponse(results: [scoreOnServer], count: 1) @@ -312,7 +312,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length var scoreOnServer = GameScore(score: 10) scoreOnServer.objectId = "yarr" scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil let results = QueryResponse(results: [scoreOnServer], count: 1) @@ -331,7 +331,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length var scoreOnServer = GameScore(score: 10) scoreOnServer.objectId = "yarr" scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil let results = QueryResponse(results: [scoreOnServer], count: 1) @@ -427,7 +427,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length var scoreOnServer = GameScore(score: 10) scoreOnServer.objectId = "yarr" scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil let results = QueryResponse(results: [scoreOnServer], count: 1) @@ -449,7 +449,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length var scoreOnServer = GameScore(score: 10) scoreOnServer.objectId = "yarr" scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil let results = QueryResponse(results: [scoreOnServer], count: 1) @@ -499,7 +499,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length var scoreOnServer = GameScore(score: 10) scoreOnServer.objectId = "yarr" scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil let results = QueryResponse(results: [scoreOnServer], count: 1) @@ -544,7 +544,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length var scoreOnServer = GameScore(score: 10) scoreOnServer.objectId = "yarr" scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil let results = QueryResponse(results: [scoreOnServer], count: 1) @@ -566,7 +566,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length var scoreOnServer = GameScore(score: 10) scoreOnServer.objectId = "yarr" scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil let results = QueryResponse(results: [scoreOnServer], count: 1) @@ -2187,7 +2187,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length var scoreOnServer = GameScore(score: 10) scoreOnServer.objectId = "yarr" scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil let results = QueryResponse(results: [scoreOnServer], count: 1) @@ -2217,7 +2217,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length var scoreOnServer = GameScore(score: 10) scoreOnServer.objectId = "yarr" scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil let results = QueryResponse(results: [scoreOnServer], count: 1) @@ -2285,7 +2285,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length var scoreOnServer = GameScore(score: 10) scoreOnServer.objectId = "yarr" scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = Date() + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil let results = QueryResponse(results: [scoreOnServer], count: 1) diff --git a/Tests/ParseSwiftTests/ParseUserCombineTests.swift b/Tests/ParseSwiftTests/ParseUserCombineTests.swift index b505d4207..480316ddc 100644 --- a/Tests/ParseSwiftTests/ParseUserCombineTests.swift +++ b/Tests/ParseSwiftTests/ParseUserCombineTests.swift @@ -52,8 +52,9 @@ class ParseUserCombineTests: XCTestCase { // swiftlint:disable:this type_body_le var customKey: String? init() { - self.createdAt = Date() - self.updatedAt = Date() + let date = Date() + self.createdAt = date + self.updatedAt = date self.objectId = "yarr" self.ACL = nil self.customKey = "blah" diff --git a/Tests/ParseSwiftTests/ParseUserTests.swift b/Tests/ParseSwiftTests/ParseUserTests.swift index b5882890b..80a7844b5 100644 --- a/Tests/ParseSwiftTests/ParseUserTests.swift +++ b/Tests/ParseSwiftTests/ParseUserTests.swift @@ -48,8 +48,9 @@ class ParseUserTests: XCTestCase { // swiftlint:disable:this type_body_length var customKey: String? init() { - self.createdAt = Date() - self.updatedAt = Date() + let date = Date() + self.createdAt = date + self.updatedAt = date self.objectId = "yarr" self.ACL = nil self.customKey = "blah" @@ -144,7 +145,7 @@ class ParseUserTests: XCTestCase { // swiftlint:disable:this type_body_length var userOnServer = user userOnServer.createdAt = Date() - userOnServer.updatedAt = Date() + userOnServer.updatedAt = userOnServer.createdAt userOnServer.ACL = nil let encoded: Data! do { From 3e0fdda079e9dda64a7b1846ea4ef1e63bea7484 Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Mon, 1 Feb 2021 20:28:04 -0500 Subject: [PATCH 8/8] nits --- Tests/ParseSwiftTests/ParseObjectTests.swift | 4 ++-- Tests/ParseSwiftTests/ParsePointerTests.swift | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/ParseSwiftTests/ParseObjectTests.swift b/Tests/ParseSwiftTests/ParseObjectTests.swift index 2e7e4689e..8d9fe16ad 100644 --- a/Tests/ParseSwiftTests/ParseObjectTests.swift +++ b/Tests/ParseSwiftTests/ParseObjectTests.swift @@ -1217,7 +1217,7 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length var levelOnServer = score levelOnServer.createdAt = Date() - levelOnServer.updatedAt = levelOnServer.updatedAt + levelOnServer.updatedAt = levelOnServer.createdAt levelOnServer.ACL = nil levelOnServer.objectId = "yarr" let pointer = try levelOnServer.toPointer() @@ -1369,7 +1369,7 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length var gameOnServer = game gameOnServer.objectId = "nice" gameOnServer.createdAt = Date() - gameOnServer.updatedAt = gameOnServer.updatedAt + gameOnServer.updatedAt = gameOnServer.createdAt gameOnServer.profilePicture = savedFile let encodedGamed: Data diff --git a/Tests/ParseSwiftTests/ParsePointerTests.swift b/Tests/ParseSwiftTests/ParsePointerTests.swift index 4d93b6713..80245ae46 100644 --- a/Tests/ParseSwiftTests/ParsePointerTests.swift +++ b/Tests/ParseSwiftTests/ParsePointerTests.swift @@ -193,7 +193,7 @@ class ParsePointerTests: XCTestCase { var scoreOnServer = score scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = scoreOnServer.updatedAt + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil let encoded: Data! @@ -223,7 +223,7 @@ class ParsePointerTests: XCTestCase { var scoreOnServer = score scoreOnServer.createdAt = Date() - scoreOnServer.updatedAt = scoreOnServer.updatedAt + scoreOnServer.updatedAt = scoreOnServer.createdAt scoreOnServer.ACL = nil let encoded: Data! do {