Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ActivityIndicatorDemoController: DemoTableViewController {
return UITableViewCell()
}

cell.setup(action1Title: row.title)
cell.setup(action1Title: isAnimating ? "Stop Activity" : "Start Activity")
cell.action1Button.addTarget(self,
action: #selector(startStopActivity),
for: .touchUpInside)
Expand Down Expand Up @@ -191,7 +191,7 @@ class ActivityIndicatorDemoController: DemoTableViewController {
case .hidesWhenStopped:
return "Hides when stopped"
case .startStopActivity:
return "Start / Stop activity"
return ""
case .demoOfSize:
return ""
}
Expand Down Expand Up @@ -235,6 +235,13 @@ class ActivityIndicatorDemoController: DemoTableViewController {

@objc private func startStopActivity() {
isAnimating.toggle()

guard let section: Int = ActivityIndicatorDemoSection.allCases.firstIndex(of: .settings),
let row: Int = ActivityIndicatorDemoSection.settings.rows.firstIndex(of: .startStopActivity) else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: we avoid declaring types for inline variables unless strictly needed. See the specific reference in our style guide at Type Inference | swift-guide (microsoft.github.io)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on the linked guide, it would still make sense to declare types in such cases. Here Int is not directly used as literal. It is the result of a function firstIndex on another type. So for quick understanding, I think it is helpful to have the type Int specified here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The guide is consistent on this point:

Use type annotation as little as possible when declaring a constant or a variable; instead let the compiler infer the variable type.

Let the compiler infer the type of a constant or variable whenever possible.

The primary exception to this policy is for stored properties; local variables should almost never need a type declared, particularly when they are storing the result of a well-understood method like firstIndex.

return
}
// Reloading row to update the button title
tableView.reloadRows(at: [.init(row: row, section: section)], with: .automatic)
}
}

Expand Down