Conversation
| func setUserProfileImage(imageData: Data) { | ||
| DispatchQueue.main.async { | ||
| self.editProfileButton.isEnabled = false | ||
| self.profileImageView.image = UIImage(data: imageData)! |
There was a problem hiding this comment.
self.profileImageView.image = UIImage(data: imageData)!の右辺は
UIImage(data: imageData) ?? UIImage()が良さそうです
| editProfileButton.isEnabled = false | ||
| editProfileButton.layer.cornerRadius = 10.0 | ||
| profileImageView.layer.cornerRadius = profileImageView.frame.height / 2 |
There was a problem hiding this comment.
ここの3行はそれぞれの変数に対して関数で切り分けたほうがいいと思います!
| self.firestore.collection("message/v1/users").document("y783WJnXJqDfDED0nBvK").getDocument { (document, error) in | ||
| if let error = error { | ||
| print("Error: \(error.localizedDescription)") | ||
| return | ||
| } | ||
|
|
||
| guard let document = document, document.exists else { | ||
| print("The document doesn't exist.") | ||
| return | ||
| } | ||
|
|
||
| do { | ||
| let user = try Firestore.Decoder().decode(User.self, from: document.data()!) | ||
| self.presenter.successFetchUser(user: user) | ||
| self.downloadProfile(downLoadURL: user.profileImageURL ?? "") | ||
| } catch { | ||
| fatalError() | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
There was a problem hiding this comment.
ここはlistenerの方がuserのdisplayNameやprofileImageURLを変えた時に更新しなくて良くなるのでいいと思います!
それとusersのdocumentIDはauthのuidと一緒なので
guard let uid = Auth.auth().currentUser?.uid else { return }
let userReference = Firestore.firestore()collection("message/v1/users").document(uid)
listner = userReference.addSnapshotListener { (snapshot,error) in
エラーじゃない場合はpresenterのsuccessFetchUserを呼ぶ
}
っていう感じになると思います
| private func downloadProfile(downLoadURL: String) { | ||
| let httpsReference = Storage.storage().reference(forURL: downLoadURL) | ||
| httpsReference.getData(maxSize: 1 * 512 * 512) { data, error in | ||
| if let error = error { | ||
| print(error.localizedDescription) | ||
| return | ||
| } | ||
|
|
||
| guard let data = data else { | ||
| return | ||
| } | ||
|
|
||
| self.presenter.successFetchImageData(imageData: data) | ||
| } |
There was a problem hiding this comment.
userを取ってくる処理だけしてimageViewにuserのプロフィール画像を入れる処理はNukeに任せたほうがいいです!
import Nuke
して
let options = ImageLoadingOptions(placeholder: デフォルトの画像, failureImage: 失敗した時の画像)
loadImage(with: userのprofileImageURL, options: options, into: profileImageView, progress: nil, completion: nil)
こんな感じでしょうか
Nukeについてはoptionsとかも色々あるので調べた方が良いかもです!
| var userName = "" | ||
| var profileImage = UIImage() |
There was a problem hiding this comment.
UserProfileViewControllerからEditProfileViewControllerにへの値渡しはViewBuilderを介して行った方が良いです!
UserProfileViewControllerで
func presentEditProfileViewController(user: User) {
let editProfileVC = EditProfileViewBuilder.create(user: user)
let navigationController = UINavigationController(rootViewController: editProfileVC)
navigationController.modalPresentationStyle = .fullScreen
present(navigationController, animated: true, completion: nil)
}
こんな感じになるようにして
struct EditProfileViewBuilder {
static func create(user: User) -> UIViewController {
guard let EditProfileViewController = EditProfileViewController.loadFromStoryboard() as? EditProfileViewController else {
fatalError("fatal: Failed to initialize the EditProfileViewController")
}
let model = EditProfileModel()
let presenter = EditProfileViewPresenter(model: model, user: user)
EditProfileViewController.inject(with: presenter)
return EditProfileViewController
}
}
EditProfileViewBuilderはこんな感じでしょうか
There was a problem hiding this comment.
値の受け渡し、もう少し調べてから頑張ります。。
| } | ||
|
|
||
| func setupNameTextField() { | ||
| self.nameTextField.text = self.userName |
There was a problem hiding this comment.
presenterにuserを渡すことになるので
nameTextField.text = presenter.user.displayName になります!
| } | ||
|
|
||
| func setupImageView() { | ||
| self.imageView.image = self.profileImage |
There was a problem hiding this comment.
ここもuserのprofileImageURLを使ってnukeでimageViewの画像を変えたほうがいいです!
|
それとprofileImageの保存は |
概要
• Firebaseから名前と画像を取得して表示する処理を追加
レビュー観点
レビューレベル
Lv0: まったく見ないでAcceptするLv1: ぱっとみて違和感がないかチェックしてAcceptする
Lv2: 仕様レベルまで理解して、仕様通りに動くかある程度検証してAcceptするLv3: 実際に環境で動作確認したうえでAcceptするスクリーンショット
備考