• Review code
  • swift functions

2018 KAKAO BLIND RECRUITMENT CODING TEST

    func stringToRecord(_ line: String) -> Record {
        let parsed = line.split(separator: " ")
        let msg = String(parsed[0])
        let uid = String(parsed[1])
        return Record(action: Action.fromString(msg), id: uid)
    }
    
    func recordToString(_ r: Record) -> String? {
        guard let user = users[r.id] else { return nil }
        switch r.action {
        case .enter: return "\(user.name)님이 들어왔습니다."
        case .leave: return "\(user.name)님이 나갔습니다."
        default: return nil
        }
    }


return record.map(stringToRecord)  
        .map(recordToString)       
        .filter({ $0 != nil })
        .map({ $0! })

handleSelectPhoto function

    lazy var image1Button = createButton(selector: #selector(handleSelectPhoto))
    
    @objc fileprivate func handleSelectPhoto(button: UIButton) {
        // imagePicker
        let imagePicker = CustomImagePickerController()
        imagePicker.delegate = self
        imagePicker.imageButton = button
        present(imagePicker, animated: true)
    }

함수 종류

fetch Current User Data

Auth.auth().currentUser

Synchronously gets the cached current user, or null if there is none.

the point code!

guard let uid = Auth.auth().currentUser?.uid else { return }

getDocument { (snapshot, err)}

import Firebase
import JGProgressHUD
import SDWebImage

...

    fileprivate func fetchCurrentUser() {
        // fetch some Firestore Data
        guard let uid = Auth.auth().currentUser?.uid else { return }
        Firestore.firestore().collection("users").document(uid).getDocument { (snapshot, err) in
            if let err = err {
                print(err)
                return
            }
            
            // fetch our user here
            print(snapshot?.data())
            guard let dictionary = snapshot?.data() else { return }
            let user = User(dictionary: dictionary)
        }
    }
    var user: User?
    
    fileprivate func fetchCurrentUser() {
        // fetch some Firestore Data
        guard let uid = Auth.auth().currentUser?.uid else { return }
        Firestore.firestore().collection("users").document(uid).getDocument { (snapshot, err) in
            ...
            self.user = User(dictionary: dictionary)
        }
    }

reloadData()

Reloads the rows and sections of the table view.

            self.user = User(dictionary: dictionary)
            
            self.tableView.reloadData()
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = SettingsCell(style: .default, reuseIdentifier: nil)
        
        switch indexPath.section {
        case 1:
            cell.textField.placeholder = "Enter Name"
            cell.textField.text = user?.name
        case 2:
            cell.textField.placeholder = "Enter Profession"
            cell.textField.text = user?.profession
        case 3:
            cell.textField.placeholder = "Enter Age"
            if let age = user?.age {
                cell.textField.text = String(age)
            }
        default:
            cell.textField.placeholder = "Enter Your Bio"
        }
        return cell
    }

loadUserPhoto()

SDWebImageManager

    fileprivate func loadUserPhotos() {
        guard let imageUrl = self.user?.imageUrl1, let url = URL(string: imageUrl) else { return }
        // why exactly do we use this SDWebImageManager class to load our images?
        SDWebImageManager.shared().loadImage(with: url, options: .continueInBackground, progress: nil) { (image, _, _, _, _, _) in
            self.image1Button.setImage(image?.withRenderingMode(.alwaysOriginal), for: .normal)
        }
    }

cache object this SDWebManager 이미 이미지를 다른 곳에서 불러와서 사용했다면 그 이미지를 저장된 캐시에서 바로 불러온다.

태그: ,

카테고리:

업데이트:

댓글남기기