Skip to content

Commit

Permalink
Feature/structured concurrency (#3)
Browse files Browse the repository at this point in the history
* WIP

feature/structured-concurrency

* Bump minimum swift version to 5.5 for concurrency. Remove unsafe swift flag.

feature/structured-concurrency

* Add MainActor notations to example views. Add complete concurrency checks to example projects.

feature/structured-concurrency

* Finish adding MainActor notations and Sendable conformances to library types.

feature/structured-concurrency

* Update workflow config.

feature/structured-concurrency

* Remove MainActor from configuration and style types

feature/structured-concurrency

* Remove MainActor from BackPortedButtonToggleStyle

feature/structured-concurrency
  • Loading branch information
roanutil authored Sep 21, 2022
1 parent 12f7c90 commit 3b79cd4
Show file tree
Hide file tree
Showing 17 changed files with 108 additions and 17 deletions.
19 changes: 11 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ on:

jobs:
example:
runs-on: ${{ matrix.runsOn }}
env:
DEVELOPER_DIR: "/Applications/${{ matrix.xcode }}/Contents/Developer"
runs-on: macos-12
strategy:
matrix:
include:
- xcode: "Xcode_12.5.1.app"
runsOn: macOS-11
- xcode: "Xcode_13.2.1.app"
runsOn: macOS-12
xcode:
- "13.2.1"
- "13.4.1"
- "14.0"
steps:
- uses: actions/checkout@v2
- name: Select Xcode ${{ matrix.xcode }}
run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app
- name: Format lint
run: swiftformat --lint .
- name: Lint
run: swiftlint .
- name: Run tests
run: xcodebuild -project ./Example/Example.xcodeproj -scheme Example test -destination platform='iOS Simulator',name='iPhone 11' -quiet -enableCodeCoverage YES -derivedDataPath "./output"
67 changes: 67 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/swiftui-pick-better.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1400"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "PickBetter"
BuildableName = "PickBetter"
BlueprintName = "PickBetter"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "PickBetter"
BuildableName = "PickBetter"
BlueprintName = "PickBetter"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
8 changes: 8 additions & 0 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
};
name = Debug;
Expand Down Expand Up @@ -474,6 +475,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
};
name = Release;
Expand All @@ -500,6 +502,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 14.0;
Expand Down Expand Up @@ -528,6 +531,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 14.0;
Expand Down Expand Up @@ -679,6 +683,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TVOS_DEPLOYMENT_TARGET = 14.0;
Expand Down Expand Up @@ -715,6 +720,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TVOS_DEPLOYMENT_TARGET = 14.0;
Expand All @@ -734,6 +740,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.pick-better.ExampleUITests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_TARGET_NAME = Example;
Expand All @@ -752,6 +759,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.pick-better.ExampleUITests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_TARGET_NAME = Example;
Expand Down
1 change: 1 addition & 0 deletions Example/Shared/Sources/Shared/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import PickBetter
import SwiftUI

@MainActor
public struct ContentView: View {
@State private var tab: TabOption = .singleValue
@State private var isGridStyle: Bool = true
Expand Down
2 changes: 1 addition & 1 deletion Example/Shared/Sources/Shared/Item.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

public struct Item: Identifiable {
public struct Item: Identifiable, Sendable {
public let id: Int

public init(id: Int) {
Expand Down
1 change: 1 addition & 0 deletions Example/Shared/Sources/Shared/ItemLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Foundation
import SwiftUI

@MainActor
public struct ItemLabel: View {
private let itemId: String

Expand Down
1 change: 1 addition & 0 deletions Example/Shared/Sources/Shared/LazyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Foundation
import SwiftUI

@MainActor
public struct LazyView<Content>: View where Content: View {
private let content: () -> Content

Expand Down
1 change: 1 addition & 0 deletions Example/Shared/Sources/Shared/MultiValueSelection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation
import PickBetter
import SwiftUI

@MainActor
public struct MultiValueSelection: View {
private let items: [Item]
private let isGridStyle: Bool
Expand Down
2 changes: 2 additions & 0 deletions Example/Shared/Sources/Shared/RouteView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Foundation
import SwiftUI

@MainActor
public struct RouterView<Links, Content>: View where Links: View, Content: View {
@Binding private var selection: AnyHashable
private let links: (Binding<AnyHashable>) -> Links
Expand Down Expand Up @@ -39,6 +40,7 @@ public struct RouterView<Links, Content>: View where Links: View, Content: View
}
}

@MainActor
public struct RouteView<Route, Label, Destination>: View where Route: Hashable, Label: View, Destination: View {
private let route: AnyHashable
@Binding private var selection: AnyHashable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation
import PickBetter
import SwiftUI

@MainActor
public struct SingleOptionalValueSelection: View {
private let items: [Item]
private let isGridStyle: Bool
Expand Down
1 change: 1 addition & 0 deletions Example/Shared/Sources/Shared/SingleValueSelection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation
import PickBetter
import SwiftUI

@MainActor
public struct SingleValueSelection: View {
private let items: [Item]
private let isGridStyle: Bool
Expand Down
2 changes: 1 addition & 1 deletion Example/Shared/Sources/Shared/TabOption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

public enum TabOption {
public enum TabOption: Hashable, Sendable {
case singleValue
case singleOptionalValue
case multiValue
Expand Down
8 changes: 2 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// swift-tools-version:5.4
// The swift-tools-version declares the minimum version of Swift required to build this package.
// swift-tools-version:5.5

import PackageDescription

Expand All @@ -19,9 +18,6 @@ let package = Package(
],
dependencies: [],
targets: [
.target(
name: "PickBetter",
dependencies: []
),
.target(name: "PickBetter"),
]
)
1 change: 1 addition & 0 deletions Sources/PickBetter/BetterPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation
import SwiftUI

/// A custom implementation of a 'Picker' UI element with less magic than SwiftUI's provided `Picker`
@MainActor
public struct BetterPicker<SelectionBox, ItemContent>: View where SelectionBox: BetterPickerSelection,
ItemContent: View
{
Expand Down
2 changes: 2 additions & 0 deletions Sources/PickBetter/BetterPickerSelection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,5 @@ public struct SingleSelectionWrapper<SelectionValue: Hashable>: BetterPickerSele
// Required by protocol conformance
}
}

extension SingleSelectionWrapper: Sendable where SelectionValue: Sendable {}
1 change: 1 addition & 0 deletions Sources/PickBetter/Internal/CellWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Foundation
import SwiftUI

@MainActor
struct CellWrapper<Content>: View where Content: View {
let isSelected: Bool
let content: Content
Expand Down
7 changes: 6 additions & 1 deletion Sources/PickBetter/PlainInlineBetterPickerStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@ public struct PlainInlineBetterPickerStyle: BetterPickerStyle {
}

#if DEBUG
private struct PreviewItem: Identifiable {
private struct PreviewItem: Identifiable, Sendable {
let id: String
}

@MainActor
private var items: [PreviewItem] = ["A", "B", "C"].map { PreviewItem(id: $0) }

private func itemContent(_ item: PreviewItem) -> some View {
Text(item.id)
}

@MainActor
struct PlainInlineBetterPickerStyle_Previews: PreviewProvider {
static var previews: some View {
Group {
Expand All @@ -56,6 +58,7 @@ public struct PlainInlineBetterPickerStyle: BetterPickerStyle {
}
}

@MainActor
private struct OptionalSelectionPreview: View {
@State private var selection: PreviewItem.ID? = nil

Expand All @@ -68,6 +71,7 @@ public struct PlainInlineBetterPickerStyle: BetterPickerStyle {
}
}

@MainActor
private struct SingleSelectionPreview: View {
@State private var selection: PreviewItem.ID = items.first!.id

Expand All @@ -80,6 +84,7 @@ public struct PlainInlineBetterPickerStyle: BetterPickerStyle {
}
}

@MainActor
private struct MultiSelectionPreview: View {
@State private var selection: Set<PreviewItem.ID> = []

Expand Down

0 comments on commit 3b79cd4

Please sign in to comment.