-
-
Notifications
You must be signed in to change notification settings - Fork 69
"current" ParseObjects should be immutable #267
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
Comments
Thanks for opening this issue!
|
@Vortec4800 let me know if you have any thoughts on this as well. |
I'm all for this - being able to set or unset |
To add to that I think the requirement to make a mutable copy to make changes is fine as well, as long as upon save the |
Yes, I like this logic. I've never edited the current User directly so this actually seems like a logic step to me. I think it will be better for developers to not be able to edit the current User directly so yeah, i'm in. |
Sorry for the delay in response it has been a busy week. Is there any way to make a local only change to current user now? In my flow, I assign a Previously, I was doing:
So that way the UI in the rest of the app would update (as UserModel.current?.business is defined). Would the solution to this now be to call |
Not using cloud code, you would make the change to a mutable copy of the current user: var business = Business()
business.name = name
// Completion handler:
business.save { result in
switch result {
case .success(let savedBusiness):
var mutableUser = UserModel.current?.mutable
mutableUser.business = savedBusiness
mutableUser?.save ...
case .failure(let error):
// Handle error
}
// Async/await approach:
do {
let savedBusiness = try await business.save()
var mutableUser = UserModel.current?.mutable
mutableUser.business = savedBusiness
_ = try await mutableUser?.save()
} catch {
// Handle error
} Or you can pass the mutated user to your view model directly (or using Combine or notification). After the save, the latest version should be in If you are adding the saved object to current user in cloud code the proper way to retrieve the update (before and after this change) is to use fetch |
I apologise for late reply as I was traveling offline for few weeks. Now I updated the SDK after that while and got into a breaking change with this update. I think I can rewrite most of the logic but I wonder now how to handle the workaround for Apple SignIn re-login mentioned here var currentUser = User.current
if currentUser != nil {
try? User.logout()
}
User.apple.login(user: appleIDCredential.user, identityToken: token) { result in
switch result {
case .success(let user):
User.current = currentUser
... With previous version I did not have to call extra save as all the changes had to be done only locally (server had values before and after login correct). Now it seems that I need to |
This type of call, // modifying your current code
if User.current != nil {
try? User.logout() // Doing synchronous calls are holding up your thread and not recommended. This should be an async/await call or a async completion handler call.
}
User.apple.login(user: appleIDCredential.user, identityToken: token) { result in
switch result {
case .success:
// Proceed with the rest of your after login flow
...
}
// async/await
if User.current != nil {
try await User.logout() // Async call
}
let _ = try await User.apple.login(user: appleIDCredential.user, identityToken: token)
// Proceed with the rest of your after login flow |
Uh oh!
There was an error while loading. Please reload this page.
New Feature / Enhancement Checklist
Current Limitation
Currently all objects can be set through current, like:
ParseUser.current
,ParseInstallation.current
,ParseConfig.current
. These should be mutable and when the developer wants to mutate, they make mutable copies. This prevents unintended behavior such as settingParseUser.current
tonil
directly ascurrent
should only becomenil
when using theParseUser.logout()
method. It also prevents setting to a different user incorrectly.Feature / Enhancement Description
Note: All playgrounds examples have shown how to make mutable copies instead of setting
current
directly for some time now. Many people learn how to use the SDK from the Swift playground examples.Related to a previous discussion: #22 (comment). I should have done this back before the first release, but forgot about it.
Example Use Case
Alternatives / Workarounds
Ask the the developers to make mutable copies before mutating and hope they do so. Developer's can also add a computed property that makes a copy of their object for them.
3rd Party References
The text was updated successfully, but these errors were encountered: