Skip to content

Commit 126f4f6

Browse files
authored
feat: make "current" ParseObjects immutable (#266)
* feat: make ParseUser.current, ParseInstallation.current, ParseConfig.current immutable * nits
1 parent 5860abd commit 126f4f6

File tree

75 files changed

+177
-171
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+177
-171
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22

33
### main
44

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

8+
### 2.1.0
9+
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/2.0.3...2.1.0)
10+
11+
__Improvements__
12+
- Make ParseUser.current, ParseInstallation.current, ParseConfig.current immutable. This prevents accidently setting to nil. When developers want to make changes, they should make mutable copies, mutate, then save ([#266](https://github.com/parse-community/Parse-Swift/pull/266)), thanks to [Corey Baker](https://github.com/cbaker6).
13+
814
### 2.0.3
915
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/2.0.2...2.0.3)
1016

ParseSwift.playground/Pages/1 - Your first Object.xcplaygroundpage/Contents.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ do {
3131

3232
//: Create your own value typed `ParseObject`.
3333
struct GameScore: ParseObject {
34-
//: Those are required for Object
34+
//: These are required by ParseObject
3535
var objectId: String?
3636
var createdAt: Date?
3737
var updatedAt: Date?
@@ -69,7 +69,7 @@ extension GameScore {
6969
}
7070

7171
struct GameData: ParseObject {
72-
//: Those are required for Object
72+
//: These are required by ParseObject
7373
var objectId: String?
7474
var createdAt: Date?
7575
var updatedAt: Date?

ParseSwift.playground/Pages/10 - Cloud Code.xcplaygroundpage/Contents.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct Cloud: ParseCloud {
1919
//: Return type of your Cloud Function
2020
typealias ReturnType = String
2121

22-
//: These are required for Object
22+
//: These are required by `ParseCloud`
2323
var functionJobName: String
2424

2525
//: If your cloud function takes arguments, they can be passed by creating properties:
@@ -86,7 +86,7 @@ cloudError.runFunction { result in
8686
//: Saving objects with context for beforeSave, afterSave, etc.
8787
//: Create your own value typed `ParseObject`.
8888
struct GameScore: ParseObject {
89-
//: Those are required for Object
89+
//: These are required by ParseObject
9090
var objectId: String?
9191
var createdAt: Date?
9292
var updatedAt: Date?

ParseSwift.playground/Pages/11 - LiveQuery.xcplaygroundpage/Contents.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ initializeParse()
1111

1212
//: Create your own value typed ParseObject.
1313
struct GameScore: ParseObject {
14-
//: These are required for any Object.
14+
//: These are required by `ParseObject`.
1515
var objectId: String?
1616
var createdAt: Date?
1717
var updatedAt: Date?

ParseSwift.playground/Pages/12 - Roles and Relations.xcplaygroundpage/Contents.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ PlaygroundPage.current.needsIndefiniteExecution = true
1414
initializeParse()
1515

1616
struct User: ParseUser {
17-
//: These are required for `ParseObject`.
17+
//: These are required by `ParseObject`.
1818
var objectId: String?
1919
var createdAt: Date?
2020
var updatedAt: Date?
2121
var ACL: ParseACL?
2222

23-
//: These are required for `ParseUser`.
23+
//: These are required by `ParseUser`.
2424
var username: String?
2525
var email: String?
2626
var emailVerified: Bool?

ParseSwift.playground/Pages/13 - Operations.xcplaygroundpage/Contents.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ PlaygroundPage.current.needsIndefiniteExecution = true
1414
initializeParse()
1515

1616
struct GameScore: ParseObject {
17-
//: Those are required for Object.
17+
//: These are required by ParseObject.
1818
var objectId: String?
1919
var createdAt: Date?
2020
var updatedAt: Date?

ParseSwift.playground/Pages/15 - Custom ObjectId.xcplaygroundpage/Contents.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ initializeParseCustomObjectId()
2222

2323
//: Create your own value typed `ParseObject`.
2424
struct GameScore: ParseObject {
25-
//: Those are required for Object
25+
//: These are required by ParseObject
2626
var objectId: String?
2727
var createdAt: Date?
2828
var updatedAt: Date?

ParseSwift.playground/Pages/17 - SwiftUI - Finding Objects.xcplaygroundpage/Contents.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ initializeParse()
2020
//: Create your own value typed ParseObject.
2121
struct GameScore: ParseObject {
2222

23-
//: These are required for any Object.
23+
//: These are required by `ParseObject`.
2424
var objectId: String?
2525
var createdAt: Date?
2626
var updatedAt: Date?

ParseSwift.playground/Pages/18 - SwiftUI - Finding Objects With Custom ViewModel.xcplaygroundpage/Contents.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ initializeParse()
2121
//: Create your own value typed ParseObject.
2222
struct GameScore: ParseObject {
2323

24-
//: These are required for any Object.
24+
//: These are required by `ParseObject`.
2525
var objectId: String?
2626
var createdAt: Date?
2727
var updatedAt: Date?

ParseSwift.playground/Pages/19 - SwiftUI - LiveQuery.xcplaygroundpage/Contents.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ initializeParse()
1919

2020
//: Create your own value typed ParseObject.
2121
struct GameScore: ParseObject {
22-
//: These are required for any Object.
22+
//: These are required by `ParseObject`.
2323
var objectId: String?
2424
var createdAt: Date?
2525
var updatedAt: Date?

ParseSwift.playground/Pages/3 - User - Sign Up.xcplaygroundpage/Contents.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ import ParseSwift
1414
initializeParse()
1515

1616
struct User: ParseUser {
17-
//: These are required for `ParseObject`.
17+
//: These are required by `ParseObject`.
1818
var objectId: String?
1919
var createdAt: Date?
2020
var updatedAt: Date?
2121
var ACL: ParseACL?
2222

23-
//: These are required for `ParseUser`.
23+
//: These are required by `ParseUser`.
2424
var username: String?
2525
var email: String?
2626
var emailVerified: Bool?

ParseSwift.playground/Pages/4 - User - Continued.xcplaygroundpage/Contents.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ PlaygroundPage.current.needsIndefiniteExecution = true
1414
initializeParse()
1515

1616
struct User: ParseUser {
17-
//: These are required for `ParseObject`.
17+
//: These are required by `ParseObject`.
1818
var objectId: String?
1919
var createdAt: Date?
2020
var updatedAt: Date?
2121
var ACL: ParseACL?
2222

23-
//: These are required for `ParseUser`.
23+
//: These are required by `ParseUser`.
2424
var username: String?
2525
var email: String?
2626
var emailVerified: Bool?
@@ -61,7 +61,7 @@ extension User {
6161

6262
//: Create your own value typed `ParseObject`.
6363
struct GameScore: ParseObject {
64-
//: Those are required for Object
64+
//: These are required by ParseObject
6565
var objectId: String?
6666
var createdAt: Date?
6767
var updatedAt: Date?

ParseSwift.playground/Pages/5 - ACL.xcplaygroundpage/Contents.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ do {
2424

2525
//: Create your own value typed ParseObject.
2626
struct GameScore: ParseObject {
27-
//: Those are required for Object
27+
//: These are required by ParseObject
2828
var objectId: String?
2929
var createdAt: Date?
3030
var updatedAt: Date?

ParseSwift.playground/Pages/6 - Installation.xcplaygroundpage/Contents.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ PlaygroundPage.current.needsIndefiniteExecution = true
1414
initializeParse()
1515

1616
struct Installation: ParseInstallation {
17-
//: These are required for `ParseObject`.
17+
//: These are required by `ParseObject`.
1818
var objectId: String?
1919
var createdAt: Date?
2020
var updatedAt: Date?
2121
var ACL: ParseACL?
2222

23-
//: These are required for `ParseInstallation`.
23+
//: These are required by `ParseInstallation`.
2424
var installationId: String?
2525
var deviceType: String?
2626
var deviceToken: String?

ParseSwift.playground/Pages/7 - GeoPoint.xcplaygroundpage/Contents.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ initializeParse()
1515

1616
//: Create your own value typed `ParseObject`.
1717
struct GameScore: ParseObject {
18-
//: Those are required for Object.
18+
//: These are required by ParseObject.
1919
var objectId: String?
2020
var createdAt: Date?
2121
var updatedAt: Date?

ParseSwift.playground/Pages/8 - Pointers.xcplaygroundpage/Contents.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ initializeParse()
1515

1616
//: Create your own value typed `ParseObject`.
1717
struct Book: ParseObject {
18-
//: Those are required for Object
18+
//: These are required by ParseObject
1919
var objectId: String?
2020
var createdAt: Date?
2121
var updatedAt: Date?
@@ -36,7 +36,7 @@ extension Book {
3636
}
3737

3838
struct Author: ParseObject {
39-
//: Those are required for Object.
39+
//: These are required by ParseObject.
4040
var objectId: String?
4141
var createdAt: Date?
4242
var updatedAt: Date?

ParseSwift.playground/Pages/9 - Files.xcplaygroundpage/Contents.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ initializeParse()
1515

1616
//: Create your own value typed `ParseObject`.
1717
struct GameScore: ParseObject {
18-
//: Those are required for Object
18+
//: These are required by ParseObject
1919
var objectId: String?
2020
var createdAt: Date?
2121
var updatedAt: Date?

Sources/ParseSwift/Objects/ParseInstallation.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ struct CurrentInstallationContainer<T: ParseInstallation>: Codable {
123123
}
124124

125125
// MARK: Current Installation Support
126-
extension ParseInstallation {
127-
static var currentContainer: CurrentInstallationContainer<Self> {
126+
public extension ParseInstallation {
127+
internal static var currentContainer: CurrentInstallationContainer<Self> {
128128
get {
129129
guard let installationInMemory: CurrentInstallationContainer<Self> =
130130
try? ParseStorage.shared.get(valueFor: ParseStorage.Keys.currentInstallation) else {
@@ -210,7 +210,7 @@ extension ParseInstallation {
210210

211211
- returns: Returns a `ParseInstallation` that is the current device. If there is none, returns `nil`.
212212
*/
213-
public static var current: Self? {
213+
internal(set) static var current: Self? {
214214
get {
215215
return Self.currentContainer.currentInstallation
216216
}

Sources/ParseSwift/Objects/ParseUser.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ struct CurrentUserContainer<T: ParseUser>: Codable {
9898
}
9999

100100
// MARK: Current User Support
101-
extension ParseUser {
102-
static var currentContainer: CurrentUserContainer<Self>? {
101+
public extension ParseUser {
102+
internal static var currentContainer: CurrentUserContainer<Self>? {
103103
get {
104104
guard let currentUserInMemory: CurrentUserContainer<Self>
105105
= try? ParseStorage.shared.get(valueFor: ParseStorage.Keys.currentUser) else {
@@ -137,7 +137,7 @@ extension ParseUser {
137137
- returns: Returns a `ParseUser` that is the currently logged in user. If there is none, returns `nil`.
138138
- warning: Only use `current` users on the main thread as as modifications to `current` have to be unique.
139139
*/
140-
public static var current: Self? {
140+
internal(set) static var current: Self? {
141141
get { Self.currentContainer?.currentUser }
142142
set {
143143
Self.currentContainer?.currentUser = newValue
@@ -149,7 +149,7 @@ extension ParseUser {
149149

150150
This is set by the server upon successful authentication.
151151
*/
152-
public var sessionToken: String? {
152+
var sessionToken: String? {
153153
Self.currentContainer?.sessionToken
154154
}
155155
}

Sources/ParseSwift/ParseConstants.swift

Lines changed: 1 addition & 1 deletion
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.3"
13+
static let version = "2.1.0"
1414
static let fileManagementDirectory = "parse/"
1515
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
1616
static let fileManagementLibraryDirectory = "Library/"

Sources/ParseSwift/Types/ParseACL.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -311,20 +311,20 @@ extension ParseACL {
311311
aclController = try? ParseStorage.shared.get(valueFor: ParseStorage.Keys.defaultACL)
312312
#endif
313313

314-
if aclController != nil {
315-
if !aclController!.useCurrentUser {
316-
return aclController!.defaultACL
314+
if let acl = aclController {
315+
if !acl.useCurrentUser {
316+
return acl.defaultACL
317317
} else {
318318
guard let userObjectId = BaseParseUser.current?.objectId else {
319-
return aclController!.defaultACL
319+
return acl.defaultACL
320320
}
321321

322-
guard let lastCurrentUserObjectId = aclController!.lastCurrentUserObjectId,
322+
guard let lastCurrentUserObjectId = acl.lastCurrentUserObjectId,
323323
userObjectId == lastCurrentUserObjectId else {
324324
return try setDefaultACL(ParseACL(), withAccessForCurrentUser: true)
325325
}
326326

327-
return aclController!.defaultACL
327+
return acl.defaultACL
328328
}
329329
}
330330

@@ -374,8 +374,8 @@ extension ParseACL {
374374
}
375375

376376
let aclController: DefaultACL!
377-
if modifiedACL != nil {
378-
aclController = DefaultACL(defaultACL: modifiedACL!,
377+
if let modified = modifiedACL {
378+
aclController = DefaultACL(defaultACL: modified,
379379
lastCurrentUserObjectId: currentUserObjectId,
380380
useCurrentUser: withAccessForCurrentUser)
381381
} else {

Sources/ParseSwift/Types/ParseConfig.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ struct CurrentConfigContainer<T: ParseConfig>: Codable {
119119
var currentConfig: T?
120120
}
121121

122-
extension ParseConfig {
122+
public extension ParseConfig {
123123

124-
static var currentContainer: CurrentConfigContainer<Self>? {
124+
internal static var currentContainer: CurrentConfigContainer<Self>? {
125125
get {
126126
guard let configInMemory: CurrentConfigContainer<Self> =
127127
try? ParseStorage.shared.get(valueFor: ParseStorage.Keys.currentConfig) else {
@@ -165,7 +165,7 @@ extension ParseConfig {
165165

166166
- returns: Returns the latest `ParseConfig` on this device. If there is none, returns `nil`.
167167
*/
168-
public static var current: Self? {
168+
internal(set) static var current: Self? {
169169
get {
170170
return Self.currentContainer?.currentConfig
171171
}

Tests/ParseSwiftTests/APICommandTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ class APICommandTests: XCTestCase {
4848

4949
struct User: ParseUser {
5050

51-
//: Those are required for Object
51+
//: These are required by ParseObject
5252
var objectId: String?
5353
var createdAt: Date?
5454
var updatedAt: Date?
5555
var ACL: ParseACL?
5656

57-
// provided by User
57+
// These are required by ParseUser
5858
var username: String?
5959
var email: String?
6060
var emailVerified: Bool?
@@ -73,7 +73,7 @@ class APICommandTests: XCTestCase {
7373
var updatedAt: Date?
7474
var ACL: ParseACL?
7575

76-
// provided by User
76+
// These are required by ParseUser
7777
var username: String?
7878
var email: String?
7979
var emailVerified: Bool?

Tests/ParseSwiftTests/IOS13Tests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class IOS13Tests: XCTestCase { // swiftlint:disable:this type_body_length
2525

2626
struct GameScore: ParseObject {
2727

28-
//: Those are required for Object
28+
//: These are required by ParseObject
2929
var objectId: String?
3030
var createdAt: Date?
3131
var updatedAt: Date?

0 commit comments

Comments
 (0)