-
Notifications
You must be signed in to change notification settings - Fork 1
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
[iOS] 1주차 피드백 반영 #61
Comments
문제점coordinator패턴을 도입하여 화면 전환의 책임을 넘겨 주었다. 그런데, ImagePicker객체는 ImagePickerController를 생성 및 present, dismiss하고 있으므로 coordinator 패턴을 잘 적용 하지 못하고 있다는 판단을 하게 되었다. 시도coordinator에게 ImagePickerController 화면전환을 넘겨주기 위해서 다음과 같은 방법을 시도해보았다. 1. dissmiss할 controller를 coordinator에게 매개변수로 넘겨주기func dismiss(view: UIViewController) {
view.dismiss(animated: true, completion: nil)
} 그런데, UIViewController를 매개변수로 넘겨주는 것은 기피하란다. 왜? 🤔 UIViewController를 넘겨주면 해당 매소드내에서 무슨일이 일어날지 알 수 없으므로! Controller를 외부에서 접근하고 변경하는 것은 의존성의 문제도 야기할 수 있다고 생각한다. 2. ImagePickerController를 Coordinator에서 생성하기Coordinator에서 ImagePickerController를 생성하고, present & dismiss 하려는 시도를 했다. 그러나, UIImagePickerControllerDelegate 메소드를 살펴 볼 필요가 있다. func imagePickerControllerDidCancel(_ picker: UIImagePickerController) func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) 두가지 메소드는 UIPickerController를 매개변수로 받고 있다. 해당 매개변수를 이용하여 UIImagePickerController를 present, dismiss 할 수 있는 것이다. 만약 이러한 present, dismiss를 coordinator에게 넘겨주고 싶다면, Coordinator가 UIImagePickerControllerDelegate를 채택하게 되는 이상한 구조가 탄생한다. (아니면, 내부에서 1번 방법을 택하던지) 3. Coordinator가 ImagePickerController를 기억하기Coordinator에서 ViewController를 기억할 필요가 있을까? 필요할 때 ImagePickerController를 생성하고, 다 사용 이후에는 메모리에서 제거하는 방법도 있겠지만, 여전히 Coordinator는 ImagePickerController를 프로퍼티로 가지고 있어야 한다. 좋은 방법인지 모르겠으므로 일단 보류. 4. Coordinator에서 마지막 ViewController dismiss하기func dismiss() {
self.navigationController.popViewController(animated: true)
} Coordinator가 가지고 있는 NavigationController에 ImagePickerController를 push했으므로, pop을 해주면 된다. 결론화면 전환을 위해서 UIImagePickerControllerDelegate 프로토콜 내부 메소드가 ViewController를 매개변수로 넘겨주는 만큼 |
@dahun-lee-daji |
방법은 정말 여러가지인데, 전부다 맘에드는 방법을 찾기가 어렵네요! 혹시 이런 방법은 어떨까요? 갑자기 생각났어요 새로운 delegate instance를 정의합니다. 아 좀 바보같은 의견이네요 coordinator가 dismiss의 책임을 갖고있어야는데 ;;;;; |
ㅋㅋㅋ결국 그 Delegate instance가 coordinator인거죠 |
The text was updated successfully, but these errors were encountered: