Skip to content

Updated examples for Swift #763

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

Merged
merged 14 commits into from
Aug 26, 2020
Merged
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
12 changes: 6 additions & 6 deletions _includes/common/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ PFUser *user = [PFUser currentUser];
user.ACL = [PFACL ACLWithUser:user];
```
```swift
if let user = PFUser.currentUser() {
if let user = PFUser.current() {
user.ACL = PFACL(user: user)
}
```
Expand Down Expand Up @@ -136,7 +136,7 @@ To make it super easy to create user-private ACLs for every object, we have a wa
[PFACL setDefaultACL:[PFACL ACL] withAccessForCurrentUser:YES];
```
```swift
PFACL.setDefaultACL(PFACL(), withAccessForCurrentUser: true)
PFACL.setDefault(PFACL(), withAccessForCurrentUser: true)
```
</div>
{% endif %}
Expand Down Expand Up @@ -189,7 +189,7 @@ privateData.ACL = [PFACL ACLWithUser:[PFUser currentUser]];
[[PFUser currentUser] setObject:privateData forKey:@"privateData"];
```
```swift
if let currentUser = PFUser.currentUser() {
if let currentUser = PFUser.current() {
let privateData = PFObject(className: "PrivateUserData")
privateData.ACL = PFACL(user: currentUser)
privateData.setObject("555-5309", forKey: "phoneNumber")
Expand Down Expand Up @@ -262,9 +262,9 @@ PFACL *acl = [PFACL ACL];
```
```swift
let acl = PFACL()
acl.setPublicReadAccess(true)
acl.hasPublicReadAccess = true
if let currentUser = PFUser.currentUser() {
acl.setWriteAccess(true, forUser: currentUser)
acl.setWriteAccess(true, for: currentUser)
}
```
</div>
Expand Down Expand Up @@ -314,7 +314,7 @@ $acl->setWriteAccess(ParseUser::getCurrentUser(), true);
```
{% endif %}

Sometimes it's inconvenient to manage permissions on a per-user basis, and you want to have groups of users who get treated the same (like a set of admins with special powers). Roles are are a special kind of object that let you create a group of users that can all be assigned to the ACL. The best thing about roles is that you can add and remove users from a role without having to update every single object that is restricted to that role. To create an object that is writeable only by admins:
Sometimes it's inconvenient to manage permissions on a per-user basis, and you want to have groups of users who get treated the same (like a set of admins with special powers). Roles are a special kind of object that let you create a group of users that can all be assigned to the ACL. The best thing about roles is that you can add and remove users from a role without having to update every single object that is restricted to that role. To create an object that is writeable only by admins:

{% if page.language == "objective_c-swift" %}
<div class="language-toggle" markdown="1">
Expand Down
10 changes: 5 additions & 5 deletions _includes/ios/handling-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ func callbackForGet(result: PFObject?, error: NSError?) -> Void {
print("Everything went fine!")
} else {
if let error = error {
if error.code == PFErrorCode.ErrorObjectNotFound.rawValue {
if error._code == PFErrorCode.errorObjectNotFound.rawValue {
print("Uh oh, we couldn't find the object!")
} else {
let errorString = error.userInfo!["error"] as? NSString
let errorString = error._userInfo!["error"] as? NSString
print("Error: \(errorString)")
}
}
Expand Down Expand Up @@ -95,13 +95,13 @@ func callbackForGet(result: PFObject?, error: NSError?) -> Void {
print("Everything went fine!")
} else {
if let error = error {
if error.code == PFErrorCode.ErrorObjectNotFound.rawValue {
if error._code == PFErrorCode.errorObjectNotFound.rawValue {
print("Uh oh, we couldn't find the object!")
// Now also check for connection errors:
} else if error.code == PFErrorCode.ErrorConnectionFailed.rawValue {
} else if error._code == PFErrorCode.errorConnectionFailed.rawValue {
print("Uh oh, we couldn't even connect to the Parse Cloud!")
} else {
let errorString = error.userInfo!["error"] as? NSString
let errorString = error._userInfo!["error"] as? NSString
print("Error: \(errorString)")
}
}
Expand Down
10 changes: 5 additions & 5 deletions _includes/ios/users.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ func myMethod() {
// other fields can be set just like with PFObject
user["phone"] = "415-392-0202"

user.signUpInBackgroundWithBlock {
(succeeded: Bool, error: NSError?) -> Void in
user.signUpInBackground {
(succeeded: Bool, error: Error?) -> Void in
if let error = error {
let errorString = error.userInfo["error"] as? NSString
let errorString = error.localizedDescription
// Show the errorString somewhere and let the user try again.
} else {
// Hooray! Let them use the app now.
Expand Down Expand Up @@ -143,7 +143,7 @@ PFUser *currentUser = [PFUser currentUser]; // this will now be nil
```
```swift
PFUser.logOut()
var currentUser = PFUser.currentUser() // this will now be nil
var currentUser = PFUser.current() // this will now be nil
```
</div>

Expand Down Expand Up @@ -416,7 +416,7 @@ To kick off the password reset flow, ask the user for their email address, and c
[PFUser requestPasswordResetForEmailInBackground:@"[email protected]"];
```
```swift
PFUser.requestPasswordResetForEmailInBackground("[email protected]")
PFUser.requestPasswordResetForEmail(inBackground:"[email protected]")
```
</div>

Expand Down