๐Ÿ“ฑ App Development Study/iOS๐ŸŽ

[Udemy iOS & Swift Bootcamp] ๋ฌธ์ž์—ด์„ ์œ„ํ•œ ์ƒ์ˆ˜์ฝ”๋“œํŒŒ์ผ ๋งŒ๋“ค๊ธฐ

ibelieveinme 2023. 6. 22. 23:50
728x90
import UIKit
import FirebaseAuth

class RegisterViewController: UIViewController {

    @IBOutlet weak var emailTextfield: UITextField!
    @IBOutlet weak var passwordTextfield: UITextField!
    
    @IBAction func registerPressed(_ sender: UIButton) {
        
        if let email = emailTextfield.text, let password = passwordTextfield.text {
            Auth.auth().createUser(withEmail: email, password: password) { authResult, error in
                if let e = error {
                    print(e.localizedDescription)
                }
                else {
                    self.performSegue(withIdentifier: "RegisterToChat", sender: self)
                }
            }
        }
    }
    
}

์œ„ ์ฝ”๋“œ๋Š” ํšŒ์›๊ฐ€์ž… ํ™”๋ฉด์—์„œ ์ฑ„ํŒ… ํ™”๋ฉด์œผ๋กœ ์ „ํ™˜ํ•˜๋Š” performSeque ์ฝ”๋“œ์ด๋‹ค.

์ „ํ™˜ Identifier ๊ฐ€ ๋ฌธ์ž์—ด๋กœ ์ ํ˜€ ์žˆ์–ด์„œ ์˜คํƒ€๊ฐ€ ์ƒ๊ธฐ๋ฉด ์˜ค๋ฅ˜๊ฐ€ ๋‚˜๊ณ , ๋””๋ฒ„๊น…์ด ํž˜๋“ค๋‹ค.

์ด๋Ÿฌํ•œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ๋ฌธ์ž์—ด์„ ๋ชจ์•„๋‘˜ ์ƒ์ˆ˜ํŒŒ์ผ์„ ๋งŒ๋“ค๋ฉด ์‹œ์Šคํ…œ ์—๋Ÿฌ๋ฅผ ๋„์›Œ์„œ ์ฆ‰๊ฐ ํ•ด๊ฒฐ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.


[๋ฐฉ๋ฒ•]

๋นˆ swift ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด์„œ struct ๋กœ ๋ณ€์ˆ˜๋“ค์„ ์„ ์–ธํ•ด์ค€๋‹ค.

struct Constants{
    static let registerSegue = "RegisterToChat"
    static let loginSeque = "LoginToChat"
}

์ด ๋•Œ, static ์œผ๋กœ ์„ ์–ธํ•ด์„œ ๋ฐ˜๋ณต๋œ ๊ฐ์ฒด ์ƒ์„ฑ ์—†์ด ๋ฐ”๋กœ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ค€๋‹ค.

 

import UIKit
import FirebaseAuth

class RegisterViewController: UIViewController {

    @IBOutlet weak var emailTextfield: UITextField!
    @IBOutlet weak var passwordTextfield: UITextField!
    
    @IBAction func registerPressed(_ sender: UIButton) {
        
        if let email = emailTextfield.text, let password = passwordTextfield.text {
            Auth.auth().createUser(withEmail: email, password: password) { authResult, error in
                if let e = error {
                    print(e.localizedDescription)
                }
                else {
                    self.performSegue(withIdentifier: Constants.registerSegue, sender: self)
                }
            }
        }
    }
}

์ƒ์ˆ˜๋กœ ๋ฐ”๊พผ ๋ชจ์Šต.

 

[Type Properties ๋‚ด์šฉ ์ฐธ๊ณ ]

https://docs.swift.org/swift-book/documentation/the-swift-programming-language/properties/

 

Documentation

 

docs.swift.org

 

728x90