Skip to content

Commit

Permalink
Compatible with Xcode 16.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Lumisilk committed Nov 8, 2024
1 parent 3f3f8a3 commit ea5058f
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -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"
}
}
],
Expand Down
21 changes: 14 additions & 7 deletions Example/Example/TagExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down Expand Up @@ -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
Expand Down
18 changes: 10 additions & 8 deletions Sources/AnySubviews/AnySubview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
}
}
24 changes: 7 additions & 17 deletions Sources/AnySubviews/AnySubviewsCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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])
}
}

Expand Down Expand Up @@ -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)
}
}
}
Expand Down
24 changes: 7 additions & 17 deletions Sources/AnySubviews/AnySubviewsCollectionSlice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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])
}
}

Expand Down Expand Up @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import SwiftUI

@MainActor
@dynamicMemberLookup
public struct AnyContainerValues {
private let box: Any
Expand Down

0 comments on commit ea5058f

Please sign in to comment.