S01E13: Improving the Game Flow with Swift Generics

preview_player
Показать описание


In this episode, we improve the Router and Flow components of the Engine framework by replacing the previously hardcoded String type for Question and Answer.

As shown in the first episode, we set a goal of being able to play the game with many types of questions and answers, such as text, image, audio and video. To achieve this level of flexibility, we decided to abstract the Question and Answer types by using Swift's generics.

Finally, we didn't see any failing tests after making the changes, validating that we did not break the Flow's behaviour.

Connect with us on:

Рекомендации по теме
Комментарии
Автор

Amazing tutorial love how you decided to step into Generic instead of trying to foretell the model and coupling it with the Flow. One small thing I noticed is that right now compiler is able to infer that since R.Question needs to match Question in the where clause we don't need to mark it explicitly as Hashable in the generic definition.

dziobaczy
Автор

Hi Caio and Mike, 1. could you pls explain why we write R.Question == Question, R.Answer==Answer. 2. And in the tests, why are we again introducing a String instead of a generic type in Flow<String, String, RouterSpy>. Thank you so much!

sharanyaabishek
Автор

I have a question though: I understand why we write a where clause to the definition of the Flow ("where R.Question == Question, R.Answer == Answer"), but how does the RouterSpy conform to this condition? In other words, at what point does the compiler understand that the Question and Answer types of the Flow instance (that we create in makeSUT) equal to the types in RouterSpy?

kublaios