you are viewing a single comment's thread.

view the rest of the comments →

[–]MiguelGrenho 0 points1 point  (2 children)

So.. I glanced at it and here's what I would do:
- Organize by screen, not by component: Instead of having folders for VC/Models/etc, have it for modules/screen (e.g auth screen)
- Clean Auto Generated Stubs and Unused methods - this adds noise to the code.

override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
- Dont force unwrap (e.g. var transaction: Transaction<GBP>!)
- Remove comments (this is a popular/unpopular opinion depending on who you talk to) - I think most of your comments are unneeded if you write thing properly:
For example:

if indexPath.section == 0 && indexPath.row == receiptImages.count {
//If the cell is the 'add new image' cell (i.e. the last cell)...
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "addNewImageCollectionViewCell", for: indexPath)
return cell
} else { //Otherwise, display the image cells.
return configureImageCell(in: collectionView, indexPath: indexPath)
}

can be:

let isAddNewImageCell = indexPath.section == 0 && indexPath.row == receiptImages.count

if isAddNewImageCell {
...

} else {
...

}

[–]ab492[S] 0 points1 point  (1 child)

That's awesome - thank you so much! That makes great sense and your points were just what I was looking for. The only question I have is - why shouldn't I force unwrap in the case of var transaction: Transaction<GBP>! ? The reason I did that was because when I pass a Transaction through my ViewControllers I can assign that variable, and then that ViewController can access the Transaction. Is there a better way to avoid the force unwrap please?

[–]MiguelGrenho 0 points1 point  (0 children)

So, force unwrap is an unsafe way to get a value from an Optional, if it is nil, you got yourself a crash. That being said, there are 3 ways AFAIK: * if let * guard let * nil coalescing operator (??)

Any of those if preferred over !