Skip to content

Commit 6e359ce

Browse files
authored
Update code snippets for sign up & log in view controller (#597)
* Update user-interface.md * update swift code for log in view controller
1 parent 8160560 commit 6e359ce

File tree

1 file changed

+33
-37
lines changed

1 file changed

+33
-37
lines changed

_includes/ios/user-interface.md

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ logInController.delegate = self;
2121
```swift
2222
var logInController = PFLogInViewController()
2323
logInController.delegate = self
24-
self.presentViewController(logInController, animated:true, completion: nil)
24+
self.present(logInController, animated:true, completion: nil)
2525
```
2626
</div>
2727

@@ -48,11 +48,11 @@ Any of the above features can be turned on or off. The options can be set using
4848
| PFLogInFieldsDismissButton);
4949
```
5050
```swift
51-
logInController.fields = [PFLogInFields.UsernameAndPassword,
52-
PFLogInFields.LogInButton,
53-
PFLogInFields.SignUpButton,
54-
PFLogInFields.PasswordForgotten,
55-
PFLogInFields.DismissButton]
51+
logInController.fields = [PFLogInFields.usernameAndPassword,
52+
PFLogInFields.logInButton,
53+
PFLogInFields.signUpButton,
54+
PFLogInFields.passwordForgotten,
55+
PFLogInFields.dismissButton]
5656
```
5757
</div>
5858

@@ -72,9 +72,9 @@ logInController.fields = (PFLogInFieldsUsernameAndPassword
7272
| PFLogInFieldsTwitter);
7373
```
7474
```swift
75-
logInController.fields = [PFLogInFields.UsernameAndPassword,
76-
PFLogInFields.Facebook,
77-
PFLogInFields.Twitter]
75+
logInController.fields = [PFLogInFields.usernameAndPassword,
76+
PFLogInFields.facebook,
77+
PFLogInFields.twitter]
7878
```
7979
</div>
8080

@@ -91,7 +91,7 @@ logInController.facebookPermissions = @[ @"friends_about_me" ];
9191
var logInController = PFLogInViewController()
9292
logInController.delegate = self
9393
logInController.facebookPermissions = [ "friends_about_me" ]
94-
self.presentViewController(logInController, animated:true, completion:nil)
94+
self.present(logInController, animated:true, completion:nil)
9595
```
9696
</div>
9797

@@ -112,11 +112,11 @@ When the user signs in or cancels, the `PFLogInViewController` notifies the dele
112112
```
113113
```swift
114114
func logInViewController(controller: PFLogInViewController, didLogInUser user: PFUser!) -> Void {
115-
self.dismissViewControllerAnimated(true, completion: nil)
115+
self.dismiss(animated: true, completion: nil)
116116
}
117117

118-
func logInViewControllerDidCancelLogIn(controller: PFLogInViewController) -> Void {
119-
self.dismissViewControllerAnimated(true, completion: nil)
118+
func logInViewControllerDidCancelLog(in controller: PFLogInViewController) -> Void {
119+
self.dismiss(animated: true, completion: nil)
120120
}
121121
```
122122
</div>
@@ -146,15 +146,15 @@ You might want to use your own logo or background image. You can achieve this by
146146
@end
147147
```
148148
```swift
149-
class MyLogInViewController : PFLogInViewController {
149+
class MyLogInViewController: PFLogInViewController {
150150

151151
override func viewDidLoad() {
152152
super.viewDidLoad()
153153

154-
self.view.backgroundColor = UIColor.darkGrayColor()
154+
self.view.backgroundColor = .darkGray
155155

156-
let logoView = UIImageView(image: UIImage(named:"logo.png"))
157-
self.logInView.logo = logoView
156+
let logoView = UIImageView(image: UIImage(named:"logo.png"))
157+
self.logInView?.logo = logoView
158158
}
159159

160160
}
@@ -172,7 +172,7 @@ logInController.signUpController = [[MySignUpViewController alloc] init];
172172
```swift
173173
let logInController = MyLogInViewController()
174174
logInController.signUpController = MySignUpViewController()
175-
self.presentViewController(logInController, animated: true, completion: nil)
175+
self.present(logInController, animated: true, completion: nil)
176176
```
177177
</div>
178178

@@ -272,11 +272,7 @@ signUpController.fields = (PFSignUpFieldsUsernameAndPassword
272272
| PFSignUpFieldsDismissButton);
273273
```
274274
```swift
275-
signUpController.fields = [PFSignUpFields.usernameAndPassword,
276-
PFSignUpFields.signUpButton,
277-
PFSignUpFields.email,
278-
PFSignUpFields.additional,
279-
PFSignUpFields.dismissButton]
275+
signUpController.fields = [.usernameAndPassword, .signUpButton, .email, .additional, .dismissButton]
280276
```
281277
</div>
282278

@@ -298,11 +294,11 @@ When the user signs up or cancels, the `PFSignUpViewController` notifies the del
298294
```
299295
```swift
300296
func signUpViewController(signUpController: PFSignUpViewController, didSignUpUser user: PFUser) -> Void {
301-
self.dismissViewControllerAnimated(true, completion: nil)
297+
self.dismiss(animated: true, completion: nil)
302298
}
303299

304300
func signUpViewControllerDidCancelSignUp(signUpController: PFSignUpViewController) -> Void {
305-
self.dismissViewControllerAnimated(true, completion: nil)
301+
self.dismiss(animated: true, completion: nil)
306302
}
307303
```
308304
</div>
@@ -338,10 +334,10 @@ class MySignUpViewController : PFSignUpViewController {
338334
override func viewDidLoad() {
339335
super.viewDidLoad()
340336

341-
self.view.backgroundColor = UIColor.darkGrayColor()
337+
self.view.backgroundColor = .darkGray
342338

343-
let logoView = UIImageView(image: UIImage(named: "logo.png"))
344-
self.signUpView.logo = logoView // 'logo' can be any UIView
339+
let logoView = UIImageView(image: UIImage(named: "logo.png"))
340+
self.signUpView?.logo = logoView // 'logo' can be any UIView
345341
}
346342
}
347343
```
@@ -360,12 +356,12 @@ Often you will want to run some client-side validation on the sign up informatio
360356
}
361357
```
362358
```swift
363-
func signUpViewController(signUpController: PFSignUpViewController!,
364-
shouldBeginSignUp info: [NSObject : AnyObject]!) -> Bool {
365-
if let password = info?["password"] as? String {
366-
return password.utf16Count >= 8
367-
}
368-
return false
359+
func signUpViewController(_ signUpController: PFSignUpViewController,
360+
shouldBeginSignUp info: [String : String]) -> Bool {
361+
if let password = info["password"] {
362+
return password.utf16.count >= 8
363+
}
364+
return false
369365
}
370366
```
371367
`info` is a dictionary that contains all sign up fields, such as username, password, email, and additional.
@@ -400,20 +396,20 @@ class MySignUpViewController : PFSignUpViewController {
400396
override func viewDidLoad() {
401397
super.viewDidLoad()
402398

403-
self.signUpView.usernameField.placeholder = "phone"
399+
self.signUpView?.usernameField?.placeholder = "phone"
404400
}
405401

406402
override func viewDidLayoutSubviews() {
407403
super.viewDidLayoutSubviews()
408404

409-
self.signUpView.signUpButton.frame = CGRectMake(...) // Set a different frame.
405+
self.signUpView?.signUpButton?.frame = CGRectMake(...) // Set a different frame.
410406
}
411407

412408
}
413409
```
414410
</div>
415411

416-
Developer interested in this kind of customization should take a look at the interface of [`PFSignUpView`](http://parseplatform.org/Parse-SDK-iOS-OSX/api/Classes/PFSignUpView.html), where all customizable properties are documented.
412+
Developers interested in this kind of customization should take a look at the interface of [`PFSignUpView`](http://parseplatform.org/Parse-SDK-iOS-OSX/api/Classes/PFSignUpView.html), where all customizable properties are documented.
417413

418414
### Portrait and Landscape
419415

0 commit comments

Comments
 (0)