Skip to content

Commit 204b3fa

Browse files
authored
Merge pull request #6948 from woocommerce/fix/warnings-in-xcode-13.3.1
Fix warnings in xcode 13.3.1
2 parents cae87f6 + d1aaf5d commit 204b3fa

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

WooCommerce/Classes/Extensions/UIViewController+Helpers.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@ extension UIViewController {
2424

2525
/// Show the X close button or a custom close button with title on the left bar button item position
2626
///
27-
func addCloseNavigationBarButton(title: String? = nil, target: Any? = self, action: Selector? = #selector(dismissVC)) {
27+
func addCloseNavigationBarButton(title: String? = nil, target: Any? = nil, action: Selector? = #selector(dismissVC)) {
28+
/// We can't make self the default value for the `target` parameter without a warning being added.
29+
/// The compiler-recommended fix for the warning causes a crash when the button is tapped.
30+
let targetOrSelf = target ?? self
2831
if let title = title {
29-
navigationItem.leftBarButtonItem = UIBarButtonItem(title: title, style: .plain, target: target, action: action)
32+
navigationItem.leftBarButtonItem = UIBarButtonItem(title: title, style: .plain, target: targetOrSelf, action: action)
3033
}
3134
else {
32-
navigationItem.leftBarButtonItem = UIBarButtonItem(image: .closeButton, style: .plain, target: target, action: action)
35+
navigationItem.leftBarButtonItem = UIBarButtonItem(image: .closeButton, style: .plain, target: targetOrSelf, action: action)
3336
navigationItem.leftBarButtonItem?.accessibilityLabel = Localization.close
3437
}
3538
}

WooCommerce/Classes/ViewRelated/Dashboard/Stats v4/StoreStatsAndTopPerformersPeriodViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ final class StoreStatsAndTopPerformersPeriodViewController: UIViewController {
5656

5757
// MARK: Subviews
5858

59-
var refreshControl: UIRefreshControl = {
59+
lazy var refreshControl: UIRefreshControl = {
6060
let refreshControl = UIRefreshControl(frame: .zero)
6161
refreshControl.addTarget(self, action: #selector(pullToRefresh), for: .valueChanged)
6262
return refreshControl

WooCommerce/Classes/ViewRelated/Products/Edit Product/Downloadable Files/Add or Edit File/ProductDownloadFileViewController.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ final class ProductDownloadFileViewController: UIViewController {
2727
self?.handleKeyboardFrameUpdate(keyboardFrame: keyboardFrame)
2828
}
2929

30-
private let updateBarButton: UIBarButtonItem = {
31-
let button = UIBarButtonItem(title: nil,
32-
style: .done,
33-
target: self,
34-
action: #selector(completeUpdating))
35-
return button
30+
private lazy var updateBarButton: UIBarButtonItem = {
31+
UIBarButtonItem(title: nil,
32+
style: .done,
33+
target: self,
34+
action: #selector(completeUpdating))
3635
}()
3736

3837
/// Init

WooCommerce/Classes/ViewRelated/ReusableViews/SwiftUI Components/SegmentedView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct SegmentedView<Content: View>: View {
2424

2525
var body: some View {
2626
HStack(spacing: 0) {
27-
ForEach(0..<views.count) { (index) in
27+
ForEach(0..<views.count, id: \.self) { (index) in
2828
VStack(spacing: 0) {
2929
getContentView(index)
3030
if index == selection {

0 commit comments

Comments
 (0)