Skip to content
Closed
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
osx_image: xcode9
language: objective-c
osx_image: xcode11.3
language: swift
stage: Build
env:
matrix:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ do {
acl?.publicWrite = true
loggedIn.ACL = acl
try loggedIn.save()
} catch let e {
e
e.localizedDescription
fatalError("\(e.localizedDescription)")
} catch let error {
error
error.localizedDescription
fatalError("\(error.localizedDescription)")
}

//var acl = ACL()
Expand Down
2 changes: 1 addition & 1 deletion ParseSwift.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='6.0' target-platform='macos' display-mode='raw' executeOnSourceChanges='false' timelineScrubberEnabled='true'>
<playground version='6.0' target-platform='macos' display-mode='raw' timelineScrubberEnabled='true' last-migration='1130'>
<pages>
<page name='1- Your first Object'/>
<page name='2- Finding Objects'/>
Expand Down
17 changes: 9 additions & 8 deletions ParseSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -440,15 +440,16 @@
TargetAttributes = {
4AA807571F794242008CD551 = {
CreatedOnToolsVersion = 9.0;
LastSwiftMigration = 1130;
ProvisioningStyle = Automatic;
};
4AB8B4F31F254AE10070F682 = {
CreatedOnToolsVersion = 9.0;
LastSwiftMigration = 0900;
LastSwiftMigration = 1130;
};
4AB8B4FC1F254AE10070F682 = {
CreatedOnToolsVersion = 9.0;
LastSwiftMigration = 0900;
LastSwiftMigration = 1130;
TestTargetID = 4AA807571F794242008CD551;
};
4AFDA7111F26D9A5002AE4FC = {
Expand Down Expand Up @@ -673,7 +674,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.parse.TestHost;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -687,7 +688,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.parse.TestHost;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down Expand Up @@ -823,7 +824,7 @@
PRODUCT_NAME = ParseSwift;
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -844,7 +845,7 @@
PRODUCT_NAME = ParseSwift;
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand All @@ -857,7 +858,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwiftTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TestHost.app/TestHost";
};
Expand All @@ -871,7 +872,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwiftTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TestHost.app/TestHost";
};
Expand Down
10 changes: 5 additions & 5 deletions Sources/ParseSwift/API/API+Commands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

internal extension API {
internal struct Command<T, U>: Encodable where T: Encodable {
struct Command<T, U>: Encodable where T: Encodable {
typealias ReturnType = U
let method: API.Method
let path: API.Endpoint
Expand Down Expand Up @@ -63,7 +63,7 @@ internal extension API {

internal extension API.Command {
// MARK: Saving
internal static func saveCommand<T>(_ object: T) -> API.Command<T, T> where T: ObjectType {
static func saveCommand<T>(_ object: T) -> API.Command<T, T> where T: ObjectType {
if object.isSaved {
return updateCommand(object)
}
Expand Down Expand Up @@ -92,7 +92,7 @@ internal extension API.Command {
}

// MARK: Fetching
internal static func fetchCommand<T>(_ object: T) throws -> API.Command<T, T> where T: ObjectType {
static func fetchCommand<T>(_ object: T) throws -> API.Command<T, T> where T: ObjectType {
guard object.isSaved else {
throw ParseError(code: .unknownError, message: "Cannot Fetch an object without id")
}
Expand All @@ -111,15 +111,15 @@ extension API.Command where T: ObjectType {
}

static func batch(commands: [API.Command<T, T>]) -> RESTBatchCommandType<T> {
let commands = commands.flatMap { (command) -> API.Command<T, T>? in
let commands = commands.compactMap { (command) -> API.Command<T, T>? in
let path = ParseConfiguration.mountPath + command.path.urlComponent
guard let body = command.body else {
return nil
}
return API.Command<T, T>(method: command.method, path: .any(path),
body: body, mapper: command.mapper)
}
let bodies = commands.flatMap { (command) -> T? in
let bodies = commands.compactMap { (command) -> T? in
return command.body
}
let mapper = { (data: Data) -> [(T, ParseError?)] in
Expand Down
16 changes: 8 additions & 8 deletions Sources/ParseSwift/API/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,22 @@ public struct API {
case useMasterKey
case sessionToken(String)
case installationId(String)

// use HashValue so we can use in a sets
public var hashValue: Int {

public func hash(into hasher: inout Hasher){
switch self {
case .useMasterKey:
return 1
hasher.combine(1)
case .sessionToken:
return 2
hasher.combine(2)
case .installationId:
return 3
hasher.combine(3)
}
}

//Check to see if the compliler handles this
/*
public static func == (lhs: API.Option, rhs: API.Option) -> Bool {
return lhs.hashValue == rhs.hashValue
}
}*/
}

internal static func getHeaders(options: API.Options) -> [String: String] {
Expand Down
4 changes: 2 additions & 2 deletions Sources/ParseSwift/Asynchronous.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ extension Querying {
}

public extension ObjectType {
public static func saveAll(options: API.Options = [],
static func saveAll(options: API.Options = [],
_ objects: Self...,
callback: @escaping ([(Self, ParseError?)]?, Error?) -> Void) {
objects.saveAll(options: options, callback: callback)
}
}

public extension Sequence where Element: ObjectType {
public func saveAll(options: API.Options = [],
func saveAll(options: API.Options = [],
callback: @escaping ([(Element, ParseError?)]?, Error?) -> Void) {
runAsync(options: options, function: self.saveAll, callback: callback)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/Encoder/ParseEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ fileprivate extension EncodingError {
/// - parameter value: The value that was invalid to encode.
/// - parameter path: The path of `CodingKey`s taken to encode this value.
/// - returns: An `EncodingError` with the appropriate path and debug description.
fileprivate static func _invalidFloatingPointValue<T : FloatingPoint>(_ value: T, at codingPath: [CodingKey]) -> EncodingError {
static func _invalidFloatingPointValue<T : FloatingPoint>(_ value: T, at codingPath: [CodingKey]) -> EncodingError {
let valueDescription: String
if value == T.infinity {
valueDescription = "\(T.self).infinity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

public extension ObjectType {
public static func saveAll(_ objects: Self...) throws -> [(Self, ParseError?)] {
static func saveAll(_ objects: Self...) throws -> [(Self, ParseError?)] {
return try objects.saveAll()
}
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/ParseSwift/Objects Protocols/ObjectType+Query.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
import Foundation

public extension ObjectType {
public static func find() throws -> [Self] {
static func find() throws -> [Self] {
return try query().find()
}

public static func query() -> Query<Self> {
static func query() -> Query<Self> {
return Query<Self>()
}

public static func query(_ constraints: QueryConstraint...) -> Query<Self> {
static func query(_ constraints: QueryConstraint...) -> Query<Self> {
return Query(constraints)
}
}
12 changes: 6 additions & 6 deletions Sources/ParseSwift/Objects Protocols/ObjectType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public protocol ObjectType: Fetching, Saving, CustomDebugStringConvertible, Equa
}

internal extension ObjectType {
internal func getEncoder() -> ParseEncoder {
func getEncoder() -> ParseEncoder {
return getParseEncoder()
}
}
Expand Down Expand Up @@ -102,10 +102,10 @@ let dateEncodingStrategy: JSONEncoder.DateEncodingStrategy = .custom({ (date, en
})

internal extension Date {
internal func parseFormatted() -> String {
func parseFormatted() -> String {
return dateFormatter.string(from: self)
}
internal var parseRepresentation: [String: String] {
var parseRepresentation: [String: String] {
return ["__type": "Date", "iso": parseFormatted()]
}
}
Expand Down Expand Up @@ -137,7 +137,7 @@ func getParseEncoder() -> ParseEncoder {
encoder.dateEncodingStrategy = parseDateEncodingStrategy
encoder.shouldEncodeKey = { (key, path) -> Bool in
if path.count == 0 // top level
&& forbiddenKeys.index(of: key) != nil {
&& forbiddenKeys.firstIndex(of: key) != nil {
return false
}
return true
Expand All @@ -161,11 +161,11 @@ func getDecoder() -> JSONDecoder {
}

public extension ObjectType {
public func save(options: API.Options) throws -> Self {
func save(options: API.Options) throws -> Self {
return try saveCommand().execute(options: options)
}

public func fetch(options: API.Options) throws -> Self {
func fetch(options: API.Options) throws -> Self {
return try fetchCommand().execute(options: options)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/Storage/KeychainStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

func getKeychainQueryTemplate(forService service: String) -> [String: String] {
var query = [String: String]()
if service.characters.count > 0 {
if service.count > 0 {
query[kSecAttrService as String] = service
}
query[kSecClass as String] = kSecClassGenericPassword as String
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/Types/ACL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ extension ACL {
try container.nestedContainer(keyedBy: Access.self, forKey: scope))
}.flatMap { pair -> [(String, Access, Bool)] in
let (scope, accessValues) = pair
return try accessValues.allKeys.flatMap { (access) -> (String, Access, Bool)? in
return try accessValues.allKeys.compactMap { (access) -> (String, Access, Bool)? in
guard let value = try accessValues.decodeIfPresent(Bool.self, forKey: access) else {
return nil
}
Expand Down
19 changes: 12 additions & 7 deletions Tests/ParseSwiftTests/KeychainStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ class KeychainStoreTests: XCTestCase {
let key = "yarrKey"
let value = "yarrValue"
testStore[key] = value
let storedValue: String = testStore.object(forKey: key)!
XCTAssertEqual(storedValue, value, "Values should be equal after get")
let storedValue: String? = testStore.object(forKey: key)
XCTAssertNotNil(storedValue, "Values should not be nil")
if let storedValue: String = testStore.object(forKey: key){
XCTAssertEqual(storedValue, value, "Values should be equal after get")
}
}

func testGetObjectSubscript() {
Expand Down Expand Up @@ -70,6 +73,8 @@ class KeychainStoreTests: XCTestCase {
XCTAssertNil(testStore[bool: key], "Values should be equal after get")
}

//Removed the test case below as it's currently not possible to make Any conform to Encodable. See issue/workarounds here: https://github.com/Moya/Moya/pull/1936
/*
func testSetComplextObject() {
let complexObject: [Any] = [["key": "value"], "string2", 1234, NSNull()]
testStore["complexObject"] = complexObject
Expand Down Expand Up @@ -107,19 +112,19 @@ class KeychainStoreTests: XCTestCase {
default: break
}
}
}
}*/

func testRemoveObject() {
testStore["key1"] = "value1"
XCTAssertNotNil(testStore["key1"]!, "The value should be set")
XCTAssertNotNil(testStore[string: "key1"], "The value should be set")
_ = testStore.removeObject(forKey: "key1")
let key1Val: String? = testStore["key1"]
XCTAssertNil(key1Val, "There should be no value after removal")
}

func testRemoveObjectSubscript() {
testStore["key1"] = "value1"
XCTAssertNotNil(testStore["key1"]!, "The value should be set")
XCTAssertNotNil(testStore[string: "key1"], "The value should be set")
testStore[string: "key1"] = nil
let key1Val: String? = testStore["key1"]
XCTAssertNil(key1Val, "There should be no value after removal")
Expand All @@ -128,8 +133,8 @@ class KeychainStoreTests: XCTestCase {
func testRemoveAllObjects() {
testStore["key1"] = "value1"
testStore["key2"] = "value2"
XCTAssertNotNil(testStore["key1"]!, "The value should be set")
XCTAssertNotNil(testStore["key2"]!, "The value should be set")
XCTAssertNotNil(testStore[string: "key1"], "The value should be set")
XCTAssertNotNil(testStore[string: "key2"], "The value should be set")
_ = testStore.removeAllObjects()
let key1Val: String? = testStore["key1"]
let key2Val: String? = testStore["key1"]
Expand Down