-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add cr.swift file #1
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// Netguru iOS code review task | ||
// | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You forgot about importing UIKit :) |
||
class paymentViewController: UIViewController { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I add a keyword 'final' to the view controllers, to avoid inheritance by a mistake. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would also add a 'PaymentViewControllerProtocol' to satisfy dependency inversion principle which says: "let’s make the high level and the low level structures depend on abstractions". |
||
var delegate: PaymentViewControllerDelegate | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should add 'weak' keyword to avoid ARC isssues - strong reference cycle There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you are sure that this delegate would be never a nil, you can consider using 'unowned' keyword |
||
let customView = PaymentView() | ||
let payment: Payment? | ||
Comment on lines
+7
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider encapsulating those variables, if they won't be used outside the file |
||
|
||
func callbacks() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can make the function private as it won't be used outside the view controller. |
||
view.backgroundColor = UIColor(displayP3Red: 1, green: 1, blue: 1, alpha: 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You can also use XCAssets as we might implement dark mode in the future. |
||
customView.didTapButton = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if let payment = self.payment { | ||
self.delegate.didFinishFlow(amount: payment.amount | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you forgot about a comma :) |
||
currency: payment.currency) | ||
} | ||
} | ||
} | ||
|
||
func viewDidLoad() { | ||
navigationController?.setNavigationBarHidden(false, animated: false) | ||
customView.centerXAnchor.constraint(equalTo: view.centerXAnchor) | ||
customView.centerYAnchor.constraint(equalTo: view.centerYAnchor) | ||
Comment on lines
+22
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no isActive = true for those constraints |
||
view.addSubview(customView) | ||
fetchPayment() | ||
setupCallbacks() | ||
} | ||
|
||
internal let ViewModel: PaymentViewModel | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. variable names should be in camel case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i would also bring it to the top, along the other variables |
||
|
||
func fetchPayment() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let it have some privacy 😄 |
||
customView.statusText = "Fetching data" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add this string to our L18n struct, it is a good practice to not leave hardcoded variables in controllers :) |
||
ApiClient.sharedInstance().fetchPayment { payment in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
self.CustomView.isEuro = payment.currency == "EUR" ? true : false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Compare it by enum, not it's value - in some cases, it may change in a future |
||
if payment!.amount != 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. guard would be a far better solution in my opinion There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also, I would consider a isZero, but it's not a necessity :) |
||
self.CustomView.label.text = "\(payment!.amount)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, you have misspelled customView name :) |
||
return | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would leave information about the author of the file :)