I'm getting into Swift iOS development, and decided to create a Cookie Clicker application as a first attempt. Since I am very new with Swift, I would like feedback and criticism on everything possible, to kick bad habits to the curb early. Any and all feedback is welcome, appreciated and considered!

Since all of the code that I wrote is contained in the ViewController class, I'm only posting the class. If needed, I can post other classes. A screenshot of the layout of my app will also be available below.

ViewController.swift

//MARK: Import Statements
import UIKit

class ViewController: UIViewController {

//MARK: Properties

//Labels

//Buttons

formatItems()
}

//MARK: Actions

@IBAction func upgradeClicker(_ sender: UIButton) {
for: .normal
)
}
}

@IBAction func getCookie(_ sender: UIButton) {
}

//MARK: Local Functions

func formatItems() {

}

}


App Layout Screenshot

Since there isn't much code there are only few things that can be improved and all of them are styling:

• when working with outlets, make sure to specify the outlet type in the property name. ex. cookiesPerClick -> cookiesPerClickLabel Same applies for the @IBAction. Common approach is to add buttonTapped at the end getCookieButtonTapped. A bit more android way is onAction but still acceptable

The main reason for adding those suffixes is to make it clear what are you dealing with (button action, property label or whatever)

• I would rename cookies to cookiesCount. cookies sounds more like list of cookies

• delete generated comments like // Do any additional setup after loading the view.

• If you are not gonna expose some properties/functions (cookies, cookiesAClick, cookieUpgradeCost, func formatItems()) mark them as private

• In general an "early return" strategy is preferred where applicable as opposed to nesting code in if statements. Using guard statements for this use-case is often helpful and can improve the readability of the code

@@IBAction func upgradeClicker(_ sender: UIButton) {

...
}

• You have three different views in formatItems that are styled the same way so it will be easier to maintain (and less code) to just separate the styling. I would add it in extension of UIView
extension UIView {
layer.borderWidth = 1
layer.borderColor = UIColor.black.cgColor
}


and in private func formatItems() you will only have:

private func formatItems() {