Skip to content

Commit 2bda2fd

Browse files
authored
fix: Parse ViewModels properties always dispatch to the main queue (#260)
1 parent 3934a45 commit 2bda2fd

File tree

6 files changed

+33
-11
lines changed

6 files changed

+33
-11
lines changed

CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22

33
### main
44

5-
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/2.0.1...main)
5+
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/2.0.2...main)
66
* _Contributing to this repo? Add info about your change here to be included in the next release_
77

8+
### 2.0.2
9+
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/2.0.1...2.0.2)
10+
811
__Improvements__
912
- Add static methods for accessing encoders/decoder so developers do not have to create instances to access ([#259](https://github.com/parse-community/Parse-Swift/pull/259)), thanks to [Corey Baker](https://github.com/cbaker6).
1013

14+
__Fixes__
15+
- Parse ViewModels always dispatch to the main queue when updating published properties. This prevents possible issues when background async calls update properties used for views ([#260](https://github.com/parse-community/Parse-Swift/pull/260)), thanks to [Corey Baker](https://github.com/cbaker6).
16+
1117
### 2.0.1
1218
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/2.0.0...2.0.1)
1319

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import PackageDescription
4545
let package = Package(
4646
name: "YOUR_PROJECT_NAME",
4747
dependencies: [
48-
.package(url: "https://github.com/parse-community/Parse-Swift", from: "1.10.1"),
48+
.package(url: "https://github.com/parse-community/Parse-Swift", from: "2.0.2"),
4949
]
5050
)
5151
```

Sources/ParseSwift/LiveQuery/Subscription.swift

+9-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ open class Subscription<T: ParseObject>: QueryViewModel<T>, QuerySubscribable {
7070
if newValue != nil {
7171
subscribed = nil
7272
unsubscribed = nil
73-
objectWillChange.send()
73+
DispatchQueue.main.async {
74+
self.objectWillChange.send()
75+
}
7476
}
7577
}
7678
}
@@ -81,7 +83,9 @@ open class Subscription<T: ParseObject>: QueryViewModel<T>, QuerySubscribable {
8183
if newValue != nil {
8284
unsubscribed = nil
8385
event = nil
84-
objectWillChange.send()
86+
DispatchQueue.main.async {
87+
self.objectWillChange.send()
88+
}
8589
}
8690
}
8791
}
@@ -92,7 +96,9 @@ open class Subscription<T: ParseObject>: QueryViewModel<T>, QuerySubscribable {
9296
if newValue != nil {
9397
subscribed = nil
9498
event = nil
95-
objectWillChange.send()
99+
DispatchQueue.main.async {
100+
self.objectWillChange.send()
101+
}
96102
}
97103
}
98104
}

Sources/ParseSwift/ParseConstants.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010

1111
enum ParseConstants {
1212
static let sdk = "swift"
13-
static let version = "2.0.1"
13+
static let version = "2.0.2"
1414
static let fileManagementDirectory = "parse/"
1515
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
1616
static let fileManagementLibraryDirectory = "Library/"

Sources/ParseSwift/Types/CloudViewModel.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ open class CloudViewModel<T: ParseCloud>: CloudObservable {
2222
willSet {
2323
if newValue != nil {
2424
self.error = nil
25-
objectWillChange.send()
25+
DispatchQueue.main.async {
26+
self.objectWillChange.send()
27+
}
2628
}
2729
}
2830
}
@@ -32,7 +34,9 @@ open class CloudViewModel<T: ParseCloud>: CloudObservable {
3234
willSet {
3335
if newValue != nil {
3436
self.results = nil
35-
objectWillChange.send()
37+
DispatchQueue.main.async {
38+
self.objectWillChange.send()
39+
}
3640
}
3741
}
3842
}

Sources/ParseSwift/Types/QueryViewModel.swift

+9-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ open class QueryViewModel<T: ParseObject>: QueryObservable {
2222
open var results = [Object]() {
2323
willSet {
2424
count = newValue.count
25-
objectWillChange.send()
25+
DispatchQueue.main.async {
26+
self.objectWillChange.send()
27+
}
2628
}
2729
}
2830

@@ -31,7 +33,9 @@ open class QueryViewModel<T: ParseObject>: QueryObservable {
3133
willSet {
3234
error = nil
3335
if newValue != results.count {
34-
objectWillChange.send()
36+
DispatchQueue.main.async {
37+
self.objectWillChange.send()
38+
}
3539
}
3640
}
3741
}
@@ -42,7 +46,9 @@ open class QueryViewModel<T: ParseObject>: QueryObservable {
4246
if newValue != nil {
4347
results.removeAll()
4448
count = results.count
45-
objectWillChange.send()
49+
DispatchQueue.main.async {
50+
self.objectWillChange.send()
51+
}
4652
}
4753
}
4854
}

0 commit comments

Comments
 (0)