Skip to content

Commit

Permalink
Merge pull request #7 from MFB-Technologies-Inc/strict-concurrency-ch…
Browse files Browse the repository at this point in the history
…ecking

Maintenance
  • Loading branch information
r-jarvis authored Oct 5, 2023
2 parents 79ba46f + 7803f25 commit 8586ee2
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 27 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ jobs:
xcode: 14.2 # Swift 5.7
sim: iPhone 14
- os: macos-13
xcode: 14.3 # Swift 5.8
xcode: 14.3.1 # Swift 5.8
sim: iPhone 14
- os: macos-13
xcode: '15.0' # Swift 5.9
sim: iPhone 15
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 2 additions & 0 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_STRICT_CONCURRENCY = complete;
};
name = Debug;
};
Expand Down Expand Up @@ -656,6 +657,7 @@
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_STRICT_CONCURRENCY = complete;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand Down
1 change: 0 additions & 1 deletion Example/Shared/Sources/Shared/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import PickBetter
import SwiftUI

@MainActor
public struct ContentView: View {
@State private var tab: TabOption = .singleValue
@State private var isGridStyle: Bool = true
Expand Down
1 change: 0 additions & 1 deletion Example/Shared/Sources/Shared/ItemLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import Foundation
import SwiftUI

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

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

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

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

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

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

@MainActor
public struct SingleValueSelection: View {
private let items: [Item]
private let isGridStyle: Bool
Expand Down
1 change: 0 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ let package = Package(
targets: ["PickBetter"]
),
],
dependencies: [],
targets: [
.target(name: "PickBetter"),
]
Expand Down
33 changes: 33 additions & 0 deletions Package@swift-5.8.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// swift-tools-version:5.8

import PackageDescription

let package = Package(
name: "swiftui-pick-better",
platforms: [
.iOS(.v14),
.macOS(.v11),
.watchOS(.v7),
.tvOS(.v14),
],
products: [
.library(
name: "PickBetter",
targets: ["PickBetter"]
),
],
targets: [
.target(name: "PickBetter"),
]
)

package.targets.strictConcurrency()

extension Array where Element == Target {
func strictConcurrency() {
forEach { target in
target.swiftSettings = (target.swiftSettings ?? [])
+ [.enableUpcomingFeature("StrictConcurrency")]
}
}
}
21 changes: 10 additions & 11 deletions Sources/PickBetter/BetterPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ 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 Expand Up @@ -67,7 +66,7 @@ public struct BetterPicker<SelectionBox, ItemContent>: View where SelectionBox:
fileprivate static func itemsFromData<Data>(
_ data: Data,
selectionValue: @escaping (Data.Element) -> SelectionValue,
content: @MainActor @escaping (Data.Element) -> ItemContent
content: @escaping (Data.Element) -> ItemContent
) -> [ItemTuple] where Data: Sequence {
data.map { item in (selectionValue(item), { content(item) }) }
}
Expand All @@ -84,7 +83,7 @@ public struct BetterPicker<SelectionBox, ItemContent>: View where SelectionBox:
_ data: Data,
selectionValue: @escaping (Data.Element) -> SelectionValue,
selection: Binding<SelectionValue>,
@ViewBuilder content: @MainActor @escaping (Data.Element) -> ItemContent
@ViewBuilder content: @escaping (Data.Element) -> ItemContent
) where Data: Sequence, SelectionBox == SingleSelectionWrapper<UnwrappedSelection> {
let selectionBinding: Binding<SingleSelectionWrapper<SelectionValue>> = Binding(
get: { SingleSelectionWrapper(value: selection.wrappedValue) },
Expand All @@ -106,7 +105,7 @@ public struct BetterPicker<SelectionBox, ItemContent>: View where SelectionBox:
_ data: Data,
selectionValue: @escaping (Data.Element) -> SelectionValue,
selection: Binding<Selection?>,
@ViewBuilder content: @MainActor @escaping (Data.Element) -> ItemContent
@ViewBuilder content: @escaping (Data.Element) -> ItemContent
) where Data: Sequence, SelectionBox == Selection? {
self.init(
items: Self.itemsFromData(data, selectionValue: selectionValue, content: content),
Expand All @@ -126,7 +125,7 @@ extension BetterPicker where SelectionBox: Sequence {
_ data: Data,
selectionValue: @escaping (Data.Element) -> SelectionValue,
selection: Binding<SelectionBox>,
@ViewBuilder content: @MainActor @escaping (Data.Element) -> ItemContent
@ViewBuilder content: @escaping (Data.Element) -> ItemContent
) where Data: Sequence, Data.Element == SelectionBox.SelectionValue {
self.init(
items: Self.itemsFromData(data, selectionValue: selectionValue, content: content),
Expand All @@ -146,7 +145,7 @@ extension BetterPicker {
public init<Data, UnwrappedSelection>(
_ data: Data,
selection: Binding<SelectionValue>,
@ViewBuilder content: @MainActor @escaping (Data.Element) -> ItemContent
@ViewBuilder content: @escaping (Data.Element) -> ItemContent
) where Data: Sequence, Data.Element == SelectionValue,
SelectionBox == SingleSelectionWrapper<UnwrappedSelection>
{
Expand All @@ -168,7 +167,7 @@ extension BetterPicker {
public init<Data, Selection>(
_ data: Data,
selection: Binding<Selection?>,
@ViewBuilder content: @MainActor @escaping (Data.Element) -> ItemContent
@ViewBuilder content: @escaping (Data.Element) -> ItemContent
) where Data: Sequence, Data.Element == Selection,
SelectionBox == Selection?
{
Expand All @@ -188,7 +187,7 @@ extension BetterPicker where SelectionBox: Sequence {
public init<Data>(
_ data: Data,
selection: Binding<SelectionBox>,
@ViewBuilder content: @MainActor @escaping (Data.Element) -> ItemContent
@ViewBuilder content: @escaping (Data.Element) -> ItemContent
) where Data: Sequence, Data.Element == SelectionBox.SelectionValue {
self.init(
items: Self.itemsFromData(data, selectionValue: { $0 }, content: content),
Expand All @@ -208,7 +207,7 @@ extension BetterPicker {
public init<Data, UnwrappedSelection>(
_ data: Data,
selection: Binding<SelectionValue>,
@ViewBuilder content: @MainActor @escaping (Data.Element) -> ItemContent
@ViewBuilder content: @escaping (Data.Element) -> ItemContent
) where Data: Sequence, Data.Element: Identifiable, Data.Element.ID == SelectionValue,
SelectionBox == SingleSelectionWrapper<UnwrappedSelection>
{
Expand All @@ -227,7 +226,7 @@ extension BetterPicker {
public init<Data, Selection>(
_ data: Data,
selection: Binding<Selection?>,
@ViewBuilder content: @MainActor @escaping (Data.Element) -> ItemContent
@ViewBuilder content: @escaping (Data.Element) -> ItemContent
) where Data: Sequence, Data.Element: Identifiable, Data.Element.ID == Selection,
SelectionBox == Selection?
{
Expand All @@ -247,7 +246,7 @@ extension BetterPicker where SelectionBox: Sequence {
public init<Data>(
_ data: Data,
selection: Binding<SelectionBox>,
@ViewBuilder content: @MainActor @escaping (Data.Element) -> ItemContent
@ViewBuilder content: @escaping (Data.Element) -> ItemContent
) where Data: Sequence, Data.Element: Identifiable, SelectionBox.Element == Data.Element.ID,
SelectionBox.Element == SelectionBox.SelectionValue
{
Expand Down
1 change: 0 additions & 1 deletion Sources/PickBetter/Internal/CellWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import Foundation
import SwiftUI

@MainActor
struct CellWrapper<Content>: View where Content: View {
let isSelected: Bool
let content: Content
Expand Down
5 changes: 0 additions & 5 deletions Sources/PickBetter/PlainInlineBetterPickerStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@ public struct PlainInlineBetterPickerStyle: BetterPickerStyle {
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 @@ -58,7 +56,6 @@ public struct PlainInlineBetterPickerStyle: BetterPickerStyle {
}
}

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

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

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

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

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

Expand Down

0 comments on commit 8586ee2

Please sign in to comment.