Skip to content
This repository has been archived by the owner on Oct 17, 2019. It is now read-only.

Finished development. #1

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open

Finished development. #1

wants to merge 26 commits into from

Conversation

PedroFabrino
Copy link
Owner

No description provided.

import RxSwift
import RxCocoa

class BaseViewController<T>: UIViewController {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you decide to create a BaseViewController instead of a protocol?

import Foundation
import ObjectMapper

class Movie: Mappable {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you do to avoid a 3rd party to do this same mapping?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use the Codale protocol, which includes encoding and decoding. The reason I choose to use ObjectMapper is for being able to work with dictionaries, instead of Data objects.

}

func upcomingMovies(for page: Int) -> Observable<[Movie]> {
if page <= lastUpcomingMoviesPage ?? 100 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where this 100 comes from? What it means?

availableGenres().map { $0 as AnyObject })
.merge()
.asObservable()
.toArray().map({ (result) -> [Movie] in

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you tell me the advantages and disadvantages of using .toArray()?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toArray() basically gets a sequence observable, which is an observable for each item and turns them into one observable, making it possible to make n requests and return a single response.

I'm not aware of any disadvantages in using it.

return Mapper<Genre>().mapArray(JSONArray: genresJson)
}
} catch {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you handle the exception caught here?

self.movie.accept(detailedMovie)

case .error(let error):
Log.error("Error: \(error.localizedDescription)")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of an error, you're only login it for development purpose. How would you handle it so the user can tell that an error has occurred?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would create another behaviourRelay, an BehaviourRelay<Error?>, and would subscribe to it on any needed view. Whenever I got an error in that log, go through error.accept(error) and let the view show to the user the way it can. In that case, I would show an alert to the user, so he can try again in a few minutes.

if let releaseDate = movie.releaseDate {
self.lblReleaseYear.text = releaseDate.string(with: .medium)
}
}).disposed(by: disposeBag)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When this subscription is going to be disposed?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As soon as it's owner is released, in that case, the MovieDetailViewController.

.orEmpty
.debounce(0.5, scheduler: MainScheduler.instance)
.asDriver(onErrorJustReturn: "")
.drive((viewModel?.searchText)!)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that you use force unwrap quite
Is this a pattern that you always follow?
If not, how would you handle a crash in this situation?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only do force unwrap in situations I'm sure it won't ever be nil, in the commented part, for instance, I'm always sure that viewModel and searchText will always be instantiated when this method is called.
Whenever I can't be sure (dealing with objects that come from a server, for instance) I use if let or guard let, to make sure.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants