Skip to content

Conversation

@zeeshansuleman
Copy link
Owner

No description provided.

Copy link
Owner Author

@zeeshansuleman zeeshansuleman left a comment

Choose a reason for hiding this comment

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

Couple of comments added to improve the code.


func callbacks() {
view.backgroundColor = UIColor(displayP3Red: 1, green: 1, blue: 1, alpha: 1)
customView.didTapButton = {
Copy link
Owner Author

Choose a reason for hiding this comment

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

Closure must be used with capture list to avoid memory leaks.

let payment: Payment?

func callbacks() {
view.backgroundColor = UIColor(displayP3Red: 1, green: 1, blue: 1, alpha: 1)
Copy link
Owner Author

Choose a reason for hiding this comment

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

create a color extension and define proper name for the colors to increase code readability, Also it will be useful to reuse the color at different places.


class paymentViewController: UIViewController {
var delegate: PaymentViewControllerDelegate
let customView = PaymentView()
Copy link
Owner Author

Choose a reason for hiding this comment

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

should be "lazy" var to load in memory when used.

//

class paymentViewController: UIViewController {
var delegate: PaymentViewControllerDelegate
Copy link
Owner Author

Choose a reason for hiding this comment

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

Use "weak" for the delegates to avoid retain cycle.

}

func viewDidLoad() {
navigationController?.setNavigationBarHidden(false, animated: false)
Copy link
Owner Author

Choose a reason for hiding this comment

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

super call for viewdidload is missing.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Also please move all the code from view did load method to a seperate method e.g setupInterface()

setupCallbacks()
}

internal let ViewModel: PaymentViewModel
Copy link
Owner Author

Choose a reason for hiding this comment

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

first character of variable name must be lowercase.


func fetchPayment() {
customView.statusText = "Fetching data"
ApiClient.sharedInstance().fetchPayment { payment in
Copy link
Owner Author

Choose a reason for hiding this comment

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

use unowned capture list in closure.

customView.statusText = "Fetching data"
ApiClient.sharedInstance().fetchPayment { payment in
self.CustomView.isEuro = payment.currency == "EUR" ? true : false
if payment!.amount != 0 {
Copy link
Owner Author

Choose a reason for hiding this comment

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

avoid force unwrapping and use if let or guard statement to avoid crash if the value is nil

ApiClient.sharedInstance().fetchPayment { payment in
self.CustomView.isEuro = payment.currency == "EUR" ? true : false
if payment!.amount != 0 {
self.CustomView.label.text = "\(payment!.amount)"
Copy link
Owner Author

Choose a reason for hiding this comment

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

remove force unwrapping here as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants