Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOS-10545 Migrating to Swift 6.0 with strict concurrency #405

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions .github/workflows/record-screenshots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ jobs:

- name: Enable screenshots recording
run: |
find . -type f -name "*.swift" -exec sed -i '' 's/isRecording = false/isRecording = true/' {} +
find . -type f -name "*.swift" -exec sed -i '' 's/record: .never/record: .failed/' {} +
Copy link
Contributor

@salavert salavert Oct 28, 2024

Choose a reason for hiding this comment

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

What we do at Latch is 1 test plan with 3 configurations so we can specify them on xcodebuild -testPlan LatchSnapshots -only-test-configuration "Record all"

Screenshot 2024-10-28 at 11 28 50

https://github.com/Telefonica/path2-ios/blob/master/LatchSnapshotTests/Helpers/LatchSnapshotTest.swift

Copy link
Contributor

Choose a reason for hiding this comment

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

if you define this env variable, if only CI executes this and you don't want a test plan to do it locally, you should be able to provide it in the makefile and set it before executing the xcodebuild call

export RECORD_SCREENSHOTS=all
xcodebuild -project .... test

Copy link
Contributor

Choose a reason for hiding this comment

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

In teory yes, tried it but didn't work, maybe I'm doing something wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it would be a good idea to investigate this in a separate ticket.


- name: Launch tests and record screenshots
run: make test
continue-on-error: true

- name: Disable screenshots recording
run: |
find . -type f -name "*.swift" -exec sed -i '' 's/isRecording = true/isRecording = false/' {} +
find . -type f -name "*.swift" -exec sed -i '' 's/record: .failed/record: .never/' {} +

- name: Commit Changes
uses: stefanzweifel/git-auto-commit-action@v5
Expand Down
6 changes: 4 additions & 2 deletions MisticaCatalog/MisticaCatalog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 6.0;
};
name = Debug;
};
Expand Down Expand Up @@ -685,6 +686,7 @@
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_VERSION = 6.0;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand All @@ -710,7 +712,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.tid.mistica.enterprise;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "development-mistica";
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
};
name = Debug;
};
Expand All @@ -735,7 +737,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.tid.mistica.enterprise;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "distribution-mistica";
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
};
name = Release;
};
Expand Down
4 changes: 2 additions & 2 deletions MisticaCatalog/Source/Catalog/CatalogList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct CatalogList: View {
}

private extension CatalogRow {
@ViewBuilder
@MainActor @ViewBuilder
var swiftUIComponent: some View {
switch self {
case .badge:
Expand Down Expand Up @@ -105,7 +105,7 @@ private extension CatalogRow {
}
}

@ViewBuilder
@MainActor @ViewBuilder
var uiKitComponent: some View {
switch self {
case .buttons:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class UICatalogButtonsViewController: UITableViewController {
]
}

static var additionalButtonSections: [(name: String, buttons: [Button], contentMode: UIView.ContentMode)] = [
@MainActor static let additionalButtonSections: [(name: String, buttons: [Button], contentMode: UIView.ContentMode)] = [
("Min width", [
Button(style: .primary, title: "OK"),
Button(style: .primary, title: "OK", isSmall: true),
Expand Down Expand Up @@ -215,7 +215,7 @@ private class LoadSimulationButton: Button {
}

private extension Button.State {
func makeButton(
@MainActor func makeButton(
style: Button.Style,
title _: String,
loadingTitle _: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@ extension UICatalogEmptyStateViewController: UITableViewDataSource, UITableViewD
view.endEditing(true)

let actions: EmptyStateConfiguration.EmptyStateActions
let handler: () -> Void = {
CroutonController.shared.showCrouton(config: SnackbarConfig(title: "The user has tapped any button", dismissInterval: .fiveSeconds))
let handler: @Sendable() -> Void = {
Task { @MainActor in
CroutonController.shared.showCrouton(config: SnackbarConfig(title: "The user has tapped any button", dismissInterval: .fiveSeconds))
}
}
switch buttonsCell.segmentedControl.selectedSegmentIndex {
case 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ private extension UICatalogFeedbacksViewController {
return .none
case 1:
let primaryActionCompletion: FeedbackCompletion = { [weak self] in
self?.showAlert(withTitle: "Primary Action", message: nil, cancelActionTitle: "OK")
Task { @MainActor in
self?.showAlert(withTitle: "Primary Action", message: nil, cancelActionTitle: "OK")
}
}
return .button(title: title, completion: primaryActionCompletion)
case 2:
Expand All @@ -284,7 +286,9 @@ private extension UICatalogFeedbacksViewController {

func buildSecondaryAction(for selectedIndex: Int, title: String) -> FeedbackSecondaryAction {
let secondaryActionCompletion: FeedbackCompletion = { [weak self] in
self?.showAlert(withTitle: "Secondary Action", message: nil, cancelActionTitle: "OK")
Task { @MainActor in
self?.showAlert(withTitle: "Secondary Action", message: nil, cancelActionTitle: "OK")
}
}

switch selectedIndex {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import MisticaSwiftUI
import SwiftUI

struct ButtonsCatalogView: View {
@MainActor
private enum Constants {
static var styles: [Style] {
[
Expand Down
2 changes: 1 addition & 1 deletion MisticaCatalog/Source/ColorsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct Searchable: ViewModifier {
}

extension UIImage {
func bordered(borderWidth: CGFloat = 1, color: UIColor) -> UIImage {
@MainActor func bordered(borderWidth: CGFloat = 1, color: UIColor) -> UIImage {
UIGraphicsBeginImageContextWithOptions(size, false, UIScreen.main.scale)
let imageRect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
draw(in: imageRect)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class UIStepperTableViewCell: UITableViewCell {
private let numberOfStepsLabel = UILabel()
private lazy var textStackView = UIStackView(arrangedSubviews: [titleLabel, numberOfStepsLabel])
private lazy var numberOfStepsStackView = UIStackView(arrangedSubviews: [textStackView, numberOfStepsStepper])
var didValueChange: ((UIStepper) -> Void)?
var didValueChange: (@MainActor @Sendable(UIStepper) -> Void)?

var minValue: Double {
get { numberOfStepsStepper.minimumValue }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class UISwitchTableViewCell: UITableViewCell {
set { `switch`.isOn = newValue }
}

public var didValueChange: ((UISwitch) -> Void)?
public var didValueChange: (@MainActor @Sendable(UISwitch) -> Void)?

public init(reuseIdentifier: String?) {
super.init(style: .default, reuseIdentifier: reuseIdentifier)
Expand Down
10 changes: 5 additions & 5 deletions MisticaCatalog/Source/MisticaCatalogApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,19 @@ struct MisticaCatalogApp: App {

func configureFontStyle(for brandStyle: BrandStyle) {
if let mapping = brandStyle.fontMapping {
FontStyle.fontNameForWeight = { weight in
FontManager.shared.fontNameForWeight = { weight in
mapping.fontName(for: weight)
}
FontStyle.uiFontNameForWeight = { weight in
FontManager.shared.uiFontNameForWeight = { weight in
mapping.UIfontName(for: weight)
}
} else {
FontStyle.fontNameForWeight = nil
FontStyle.uiFontNameForWeight = nil
FontManager.shared.fontNameForWeight = nil
FontManager.shared.uiFontNameForWeight = nil
}
}
}

extension UIColor {
static var misticaCatalogTint = UIColor(hex: "#0066FF")!
static let misticaCatalogTint = UIColor(hex: "#0066FF")!
}
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.9
// swift-tools-version:6.0

import PackageDescription

Expand All @@ -15,7 +15,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/airbnb/lottie-spm.git", exact: "4.5.0"),
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing.git", exact: "1.8.2"),
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing.git", exact: "1.17.6"),
.package(url: "https://github.com/SDWebImage/SDWebImage.git", exact: "5.19.1"),
.package(url: "https://github.com/SDWebImage/SDWebImageSVGCoder.git", exact: "1.7.0")
],
Expand Down
1 change: 1 addition & 0 deletions Sources/Mistica/Components/Badge/NovumBarButtonItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import UIKit
/// Creates a UITabBarItem with the Badge style of Novum
/// - Parameters:
/// - badgeValue: The number to show in the badge or 0 for do not display it.
@MainActor
public func createNovumTabBarItem(badgeValue: UInt = 0) -> UITabBarItem {
let item = UITabBarItem()
item.badgeColor = .badge
Expand Down
6 changes: 3 additions & 3 deletions Sources/Mistica/Components/Button/ButtonStyle+Toolkit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public extension Button.Style {
private static var smallFont: UIFont { .textPreset2(weight: .button) }
private static var linkFont: UIFont { .textPreset2(weight: .button) }

private static var regularMinimumWidth: CGFloat = 156
private static var smallMinimumWidth: CGFloat = 104
private static var linkMinimumWidth: CGFloat = 0
private static let regularMinimumWidth: CGFloat = 156
private static let smallMinimumWidth: CGFloat = 104
private static let linkMinimumWidth: CGFloat = 0

private enum ImageHeight {
static let regular: CGFloat = 24
Expand Down
2 changes: 1 addition & 1 deletion Sources/Mistica/Components/Callout/Callout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class Callout: UIView {
if let contentConfiguration = contentConfiguration {
configure(withConfiguration: contentConfiguration)
} else {
configure(withConfiguration: .emptyConfiguration)
configure(withConfiguration: .emptyConfiguration())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import Foundation
import UIKit

public struct CalloutConfiguration {
static let emptyConfiguration = CalloutConfiguration(asset: .none, title: nil, description: "Empty configuration", actions: nil, canClose: true)
public static func emptyConfiguration() -> CalloutConfiguration {
CalloutConfiguration(asset: .none, title: nil, description: "Empty configuration", actions: nil, canClose: true)
}

public enum CalloutActions {
case primary(CalloutButton)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ extension CalloutContentBase {

var descriptionTitle: String {
get {
calloutBaseView.messagesView.description
calloutBaseView.messagesView.calloutDescription
}
set {
calloutBaseView.messagesView.description = newValue
calloutBaseView.messagesView.calloutDescription = newValue
}
}

Expand Down Expand Up @@ -107,7 +107,7 @@ extension CalloutContentBase {
}

calloutBaseView.title = configuration.title
calloutBaseView.description = configuration.description
calloutBaseView.calloutTitleDescription = configuration.description

switch configuration.actions {
case let .primary(primaryButton):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extension CalloutMessagesContent {
}
}

override var description: String {
var calloutDescription: String {
get {
descriptionLabel.text!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ extension CalloutTitleActions {
}
}

override var description: String {
var calloutTitleDescription: String {
get {
messagesView.description
messagesView.calloutDescription
}
set {
messagesView.description = newValue
messagesView.calloutDescription = newValue
}
}

Expand Down
12 changes: 6 additions & 6 deletions Sources/Mistica/Components/Callout/Model/CalloutButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@

import Foundation

public struct CalloutButton {
public struct CalloutButton: Sendable {
public let title: String
public let loadingTitle: String?
public let accessibilityIdentifier: String?
public let tapHandler: (() -> Void)?
public let tapHandler: (@Sendable() -> Void)?

public init(title: String,
loadingTitle: String?,
accessibilityIdentifier: String? = nil,
tapHandler: (() -> Void)?) {
tapHandler: (@Sendable() -> Void)?) {
self.title = title
self.loadingTitle = loadingTitle
self.accessibilityIdentifier = accessibilityIdentifier
self.tapHandler = tapHandler
}
}

public struct CalloutLinkButton {
public struct CalloutLinkButton: Sendable {
public let title: String
public let accessibilityIdentifier: String?
public let tapHandler: (() -> Void)?
public let tapHandler: (@Sendable() -> Void)?

public init(title: String,
accessibilityIdentifier: String? = nil,
tapHandler: (() -> Void)?) {
tapHandler: (@Sendable() -> Void)?) {
self.title = title
self.accessibilityIdentifier = accessibilityIdentifier
self.tapHandler = tapHandler
Expand Down
16 changes: 9 additions & 7 deletions Sources/Mistica/Components/Cards/DataCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class DataCard: UIView {
if let contentConfiguration = contentConfiguration {
configure(with: contentConfiguration)
} else {
configure(with: .emptyConfiguration)
configure(with: .emptyConfiguration())
}
}
}
Expand Down Expand Up @@ -294,11 +294,13 @@ private extension DataCard {
}

private extension DataCardConfiguration {
static let emptyConfiguration = DataCardConfiguration(
title: "",
descriptionTitle: "",
buttons: .link(
CardLinkButton(title: "", accessibilityIdentifier: nil, tapHandler: nil)
static func emptyConfiguration() -> DataCardConfiguration {
DataCardConfiguration(
title: "",
descriptionTitle: "",
buttons: .link(
CardLinkButton(title: "", accessibilityIdentifier: nil, tapHandler: nil)
)
)
)
}
}
7 changes: 5 additions & 2 deletions Sources/Mistica/Components/Cards/MediaCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class MediaCard: UIView {
if let contentConfiguration = contentConfiguration {
configure(with: contentConfiguration)
} else {
configure(with: .emptyConfiguration)
configure(with: .emptyConfiguration())
}
}
}
Expand Down Expand Up @@ -201,5 +201,8 @@ private extension MediaCard {
}

private extension MediaCardConfiguration {
static let emptyConfiguration = MediaCardConfiguration(richMedia: UIView(), descriptionTitle: "")
@MainActor
static func emptyConfiguration() -> MediaCardConfiguration {
MediaCardConfiguration(richMedia: UIView(), descriptionTitle: "")
}
}
Loading
Loading