Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

MLIBZ-2095: bugfix for the infinite loop if dynamic keyword is not used #243

Merged
merged 1 commit into from Oct 2, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 20 additions & 18 deletions Kinvey/BackgroundFetch/AppDelegate.swift
Expand Up @@ -12,7 +12,7 @@ import PromiseKit

class Book: Entity {

var name: String?
dynamic var name: String?

override class func collectionName() -> String {
return "Book"
Expand Down Expand Up @@ -96,27 +96,27 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var promises = [AnyPromise]()

// let promiseDataStore = Promise<AnyRandomAccessCollection<Book>> { fulfill, reject in
// print("DataStore find")
// self.dataStore.find { (result: Kinvey.Result<AnyRandomAccessCollection<Book>, Swift.Error>) in
// switch result {
// case .success(let books):
// print("\(books.count) Book(s)")
// fulfill(books)
// case .failure(let error):
// print(error)
// reject(error)
// }
// }
// }
// promises.append(AnyPromise(promiseDataStore))
let promiseDataStore = Promise<AnyRandomAccessCollection<Book>> { fulfill, reject in
print("DataStore find")
self.dataStore.find { (result: Kinvey.Result<AnyRandomAccessCollection<Book>, Swift.Error>) in
switch result {
case .success(let books):
print("\(books.count) Book(s)")
fulfill(books)
case .failure(let error):
print(error)
reject(error)
}
}
}
promises.append(AnyPromise(promiseDataStore))

let promiseFileStore = Promise<[File]> { fulfill, reject in
print("Files find")
self.fileStore.find(options: nil) { (result: Kinvey.Result<[File], Swift.Error>) in
switch result {
case .success(let files):
print(files)
print("\(files.count) File(s)")
fulfill(files)
case .failure(let error):
print(error)
Expand All @@ -126,9 +126,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
promises.append(AnyPromise(promiseFileStore))

when(fulfilled: promises.map { $0.asPromise() }).then { _ in
when(fulfilled: promises.map { $0.asPromise() }).then { (result) -> Void in
print("completionHandler new data")
completionHandler(.newData)
}.catch { _ in
}.catch { (error) -> Void in
print("completionHandler failed")
completionHandler(.failed)
}
}
Expand Down