viper: наш взгляд на вопрос. ua mobile 2016
TRANSCRIPT
- ТOS
VIPER
VIPER.
VIPER.
• TDD
• Code review
• ???
VIPER.
MVC
Controller
Model View
VIPER.
MVVM
ViewController ViewModel Model
VIPER.
Presenter Data Store
(Entity) View Interactor
VIPER
Router
VIPER.
Ч « »?
VIPER.
Ч « »?
VIPER.
Ч « »?
VIPER.
class,
NSObject UIViewController
class,
NSObject
class,
NSObject
NSManagedObject
NSObject,
struct
View Presenter Interactor Data Store
(Entity)
Router
VIPER
VIPER.
VIPER.
class MoviesListModuleInitializer: NSObject {
override func awakeFromNib() {
let configurator = factory.moduleConfigurator()
configurator.configureModule(self.viewController)
}
}
VIPER.
class MoviesListModuleConfigurator {
func configureModule(viewController: ViewController) {
let presenter = Presenter()
let service = ServiceDefault()
…
viewController.presenter = presenter
presenter.builder = builder
… }
}
VIPER.
let controller = UIViewController(data: data)
let controller = UIViewController()
controller.data = data
Про е : SОРuО
VIPER.
prepareForSegue
VIPER.
class BaseViewController: UIViewController, ModuleDataTransferProtocol {
func performSegueWithIdentifier(identifier: String, configurationBlock: (destination:
ConfigurableController) -> Void) {
…
}
func prepareForSegue(segue: UIStoryboardSegue,
sender: AnyObject?)
{
var destination = segue.destinationViewController
block(destination: destination)
}
}
VIPER.
func openMovieWithId(movieId: String) {
controller.performSegueWith(block: {
destinationController in
destinationController.configureModule(movieId)
})
}
VIPER.
router.openMoviewWithId(id)
vC.pОrПormSОРuОАТtСBloМk(…)
prОpКrОForSОРuО(…)
configurationBlock(destination)
VIPER.
• NSMКnКРОНOЛjОМt
• SОrvТМО OrТОntОН ArМСТtОМturО (SOA)
• poН’
VIPER.
VIPER + Swift
VIPER.
VIPER.
View
protocol MoviesListViewInput: class {
func showData(dataStructure: DataStructure)
func showError(error: NSError)
func showEmptyView()
}
VIPER.
Presenter //
protocol MoviesListViewOutput {
func viewIsReadyToAppear()
func didSelectMovieWithIndex(index: Int)
}
//
protocol MoviesListInteractorOutput: class {
func didObtainMoviesList(movies: [Movie]?)
func didFailToObtainMoviesListWithError(error: NSError)
}
VIPER.
Interactor
//
protocol MoviesListInteractorInput {
func obtainMoviesList()
}
VIPER.
Router
//
protocol MoviesListRouterInput {
func openMovieWithId(movieId: String)
}
VIPER.
View
Presenter
Interactor
Service
viewIsReadyToAppear()
obtainData()
fetchData()
VIPER.
Service
Interactor
Presenter
completionBlock() Array <Objects>
didObtainData() Array <Objects>
VIPER.
Presenter
View
showData()
VIPER.
Service
Interactor
Presenter
View
completionBlock() Error
didFailWithError()
showError()
VIPER.
VIPER + Swift
VIPER.
View protocol WriteUsViewInput: class {
func showEmailError()
func clearInputViews()
func showSpinner()
func hideSpinner()
}
VIPER.
Presenter protocol WriteUsOutput: class {
func userRequestToWriteUs(withName name: String,
email: String,
message: String)
func userWantsToGoBack(areFieldsEmpty: Bool)
}
protocol WriteUsInteractorOutput: class {
func didSendFeedbackMessage()
func didFailToSendFeedbackMessage(error: NSError)
}
VIPER.
Interactor
protocol WriteUsInteractorInput {
func isValidEmail(email: String) -> Bool
func sendMessage(fromAuthor username: String,
email: String,
message: String)
}
VIPER.
Router protocol WriteUsRouterInput: class {
func goBackFromViewController(viewController: UIViewController)
func showAlertExitSubmitAlert(actionHandler: AlertActionsHandler)
func showAlertFeedbackSendDidSucceed()
func showAlertFeedbackSendDidFail()
}
VIPER.
View
Presenter
Interactor
userRequestToWriteUs()
isValidEmail()
VIPER.
Presenter
Interactor
Service
sendMessage()
sendMessage()
VIPER.
Presenter
Router
showFeedbackSucceed()
VIPER.
Presenter
View
showEmailError()
VIPER.
Ч
Presenter Service View Interactor
Router Local
storage
Network
client
VIPER.
•
•
•
• /
VIPER.
•
•
•
• Х « - ?»
VIPER.
VIPER?
///
class AboutViewController: UIViewController {
//
@IBOutlet weak var versionLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
let versionNumber =
NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShort
VersionString")
let buildNumber =
NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleVersi
on")
versionLabel.text = " \(versionNumber!)
(\(buildNumber!))"
}
/**
ТTunОs
*/
@IBAction func openAppstore(sender: AnyObject) {
UIApplication.sharedApplication().openURL(NSURL(string:
"https://itunes.apple.com/ru/app/lenta.ru-vse-novosti-dna-
politika/id975805914?mt=8")!)
}
}
VIPER.
•
•
• / /
• , MVP
VIPER.
Open Source
• . —
• Generamba —
• VIPER McFlurry —
• The Book of VIPER —
https://github.com/rambler-ios
VIPER.
THANKS!