diff --git a/Example/Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Example/Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 0ec215a..fb82811 100644 --- a/Example/Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Example/Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,13 +1,13 @@ { - "originHash" : "a63591fd549c0a87ae230a7bc111987d3b04cd86a4874601f0dea8e1ed96bb88", + "originHash" : "5cf8ff5eb128b6c8e32a09c483baa95069386d9dcfca3da775a3b3658ee85609", "pins" : [ { "identity" : "swift-syntax", "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-syntax.git", + "location" : "https://github.com/swiftlang/swift-syntax.git", "state" : { - "revision" : "2bc86522d115234d1f588efe2bcb4ce4be8f8b82", - "version" : "510.0.3" + "revision" : "0687f71944021d616d34d922343dcef086855920", + "version" : "600.0.1" } } ], diff --git a/Example/Example/TagExample.swift b/Example/Example/TagExample.swift index 81772a4..fd942af 100644 --- a/Example/Example/TagExample.swift +++ b/Example/Example/TagExample.swift @@ -10,16 +10,23 @@ import AnySubviews struct TagExample: View { var body: some View { - VStack { + List { BackportGroup(subviews: content) { subviews in ForEach(subviews) { subview in - if let tag = subview.containerValues.tag(for: Double.self) { - print(tag) + HStack { + subview + + Spacer() + + VStack(alignment: .trailing) { + if let tag = subview.containerValues.tag(for: Double.self) { + Text(tag.description) + } + if let tag = subview.containerValues.tag(for: String.self) { + Text(tag) + } + } } - if let tag = subview.containerValues.tag(for: String.self) { - print(tag) - } - return subview } } } diff --git a/README.md b/README.md index dea8ea8..f37094b 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,20 @@ You can check VariadicView's detail on The Moving Parts Team's blog [SwiftUI und ## Requirements -- Xcode 16 (Swift 6.0) +- Xcode 16, Swift 6.0 - iOS 13, macOS 10.15, tvOS 13, watchOS 6, visionOS 1 or later ## Installation +Please choose the following AnySubviews's version based on your Xcode and Swift version. + +| | Swift 6.0 | +| ---------- | ------------ | +| Xcode 16.0 | exact: 1.1.1 | +| Xcode 16.1 | from: 1.2.0 | + Use [Swift Package Manager](https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app) to add this package. + ``` https://github.com/Lumisilk/SwiftUI-AnySubviews.git ``` @@ -118,6 +126,7 @@ Note: Only proceed with this step when you're certain that your app's minimum su ## TODO - [ ] Enrich the error desecription of Macro `AnyEntry` +- [ ] Add Swift 5.9 Support? - [ ] Add a realistic view example using Anysubviews ## Contributing diff --git a/Sources/AnySubviews/AnySubview.swift b/Sources/AnySubviews/AnySubview.swift index 2f5edba..b25649f 100644 --- a/Sources/AnySubviews/AnySubview.swift +++ b/Sources/AnySubviews/AnySubview.swift @@ -8,7 +8,7 @@ import SwiftUI /// AnySubview bridging the gap between `Subview` on iOS 18 and later, and `_VariadicView_Children.Element` on earlier iOS versions. -public struct AnySubview: View, @preconcurrency Identifiable, Sendable { +public struct AnySubview: Identifiable { public let box: Any @@ -38,19 +38,21 @@ public struct AnySubview: View, @preconcurrency Identifiable, Sendable { } } - public var body: some View { + public var containerValues: AnyContainerValues { if #available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *) { - subview + AnyContainerValues(subview) } else { - child + AnyContainerValues(child) } } - - public var containerValues: AnyContainerValues { +} + +extension AnySubview: View { + public var body: some View { if #available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *) { - AnyContainerValues(subview) + subview } else { - AnyContainerValues(child) + child } } } diff --git a/Sources/AnySubviews/AnySubviewsCollection.swift b/Sources/AnySubviews/AnySubviewsCollection.swift index 6cb602a..3c32618 100644 --- a/Sources/AnySubviews/AnySubviewsCollection.swift +++ b/Sources/AnySubviews/AnySubviewsCollection.swift @@ -8,7 +8,7 @@ import SwiftUI /// AnySubviewsCollection bridging the gap between `SubviewsCollection` on iOS 18 and later, and `_VariadicView_Children` on earlier iOS versions. -public struct AnySubviewsCollection: RandomAccessCollection, @unchecked Sendable { +public struct AnySubviewsCollection: RandomAccessCollection { public typealias Element = AnySubview @@ -41,12 +41,10 @@ public struct AnySubviewsCollection: RandomAccessCollection, @unchecked Sendable } public subscript(position: Int) -> AnySubview { - MainActor.assumeIsolated { - if #available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *) { - AnySubview(subviews[position]) - } else { - AnySubview(children[position]) - } + if #available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *) { + AnySubview(subviews[position]) + } else { + AnySubview(children[position]) } } @@ -78,20 +76,12 @@ public struct AnySubviewsCollection: RandomAccessCollection, @unchecked Sendable if #available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *) { var iterator = subviews.makeIterator() return AnyIterator { - iterator.next().map { subview in - MainActor.assumeIsolated { - AnySubview(subview) - } - } + iterator.next().map(AnySubview.init) } } else { var iterator = children.makeIterator() return AnyIterator { - iterator.next().map { child in - MainActor.assumeIsolated { - AnySubview(child) - } - } + iterator.next().map(AnySubview.init) } } } diff --git a/Sources/AnySubviews/AnySubviewsCollectionSlice.swift b/Sources/AnySubviews/AnySubviewsCollectionSlice.swift index 1e636ca..e78cb00 100644 --- a/Sources/AnySubviews/AnySubviewsCollectionSlice.swift +++ b/Sources/AnySubviews/AnySubviewsCollectionSlice.swift @@ -8,7 +8,7 @@ import SwiftUI /// AnySubviewsCollectionSlice bridging the gap between `SubviewsCollectionSlice` on iOS 18 and later, and `Slice<_VariadicView_Children>` on earlier iOS versions. -public struct AnySubviewsCollectionSlice: RandomAccessCollection, @unchecked Sendable { +public struct AnySubviewsCollectionSlice: RandomAccessCollection { public typealias Element = AnySubview @@ -41,12 +41,10 @@ public struct AnySubviewsCollectionSlice: RandomAccessCollection, @unchecked Sen } public subscript(position: Int) -> AnySubview { - MainActor.assumeIsolated { - if #available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *) { - AnySubview(subviews[position]) - } else { - AnySubview(children[position]) - } + if #available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *) { + AnySubview(subviews[position]) + } else { + AnySubview(children[position]) } } @@ -78,20 +76,12 @@ public struct AnySubviewsCollectionSlice: RandomAccessCollection, @unchecked Sen if #available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *) { var iterator = subviews.makeIterator() return AnyIterator { - iterator.next().map { subview in - MainActor.assumeIsolated { - AnySubview(subview) - } - } + iterator.next().map(AnySubview.init) } } else { var iterator = children.makeIterator() return AnyIterator { - iterator.next().map { child in - MainActor.assumeIsolated { - AnySubview(child) - } - } + iterator.next().map(AnySubview.init) } } } diff --git a/Sources/AnySubviews/ContainerValues/AnyContainerValues.swift b/Sources/AnySubviews/ContainerValues/AnyContainerValues.swift index 1f99e39..c2e7948 100644 --- a/Sources/AnySubviews/ContainerValues/AnyContainerValues.swift +++ b/Sources/AnySubviews/ContainerValues/AnyContainerValues.swift @@ -7,7 +7,6 @@ import SwiftUI -@MainActor @dynamicMemberLookup public struct AnyContainerValues { private let box: Any