나는 구조에서 매우 유사하다 3 가지 방법이있어, 나는이처럼 보이는, 일반적인 방법을 추출하고 싶습니다 :iOS Swift : 유형을 입력 매개 변수로 사용하여 일반적인 방법을 추출 하시겠습니까?
private func navigateToViewController(animated: Bool, viewControllerType: T, viewControllerNibName: String, mode: MenuMode) { ... }
을하지만, 나는 형식 매개 변수를 처리하는 방법을 모른다, 어떤 좋은 제안? 감사!
private func navigateToEditorView(animated: Bool) {
self.dismiss(animated: false, completion: nil)
if self.editorViewController == nil {
let editor = EditorViewController(nibName:"EditorViewController", bundle: nil)
editor.exitCallBack = self.setBackgroundImage
self.editorViewController = editor
}
if let editor = self.editorViewController {
self.navigationController?.pushViewController(editor, animated: animated)
}
self.currentMenuMode = .editor
}
private func navigateToStorageView(animated: Bool) {
self.dismiss(animated: false, completion: nil)
if self.storageViewController == nil {
let storage = StorageViewController(nibName:"StorageViewController", bundle: nil)
storage.exitCallBack = self.setBackgroundImage
self.storageViewController = storage
}
if let storage = self.storageViewController {
self.navigationController?.pushViewController(storage, animated: animated)
}
self.currentMenuMode = .storage
}
private func navigateToGalleryView(animated: Bool) {
self.dismiss(animated: false, completion: nil)
if self.galleryViewController == nil {
let gallery = GalleryViewController(nibName:"GalleryViewController", bundle: nil)
gallery.exitCallBack = self.setBackgroundImage
self.galleryViewController = gallery
}
if let gallery = self.galleryViewController {
self.navigationController?.pushViewController(gallery, animated: animated)
}
self.currentMenuMode = .gallery
}
한 문제를 하나의 일반적인 방법으로이 코드를 리팩토링 노력으로는 세 가지 다른'xxxViewController' 속성의 사용이다. – rmaddy