# How Swift Opaque Types deploy on earlier OSs

**URL:** <https://forums.swift.org/t/how-swift-opaque-types-deploy-on-earlier-oss/49489>\
**Category:** Using Swift\
**Tags:** opaque-types\
**Created:** [June 10, 2021, 7:07pm UTC](https://forums.swift.org/t/how-swift-opaque-types-deploy-on-earlier-oss/49489 "2021-06-10T19:07:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![limchihi](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@limchihi](https://forums.swift.org/u/limchihi)\
**Post date:** [June 10, 2021, 7:07pm UTC](https://forums.swift.org/t/how-swift-opaque-types-deploy-on-earlier-oss/49489/1 "2021-06-10T19:07:23Z")

</div>

Hi all. Opaque Types only can deploy on iOS13 or later OS.  
Is there any possibility that this feature could be deployed to an earlier system?  
I have a idea that use a script in release build.  
Changed this

```swift
var body: some View {
    Text("foo")
}

```

to

```swift
var body: Text {
    Text("foo")
}

```

Is this achievable? Or may be have a better way to use `some` in earlier system

---

<div class="post-metadata">

**Author:** ![toph42](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/toph42/32/7807_2.png) [@toph42](https://forums.swift.org/u/toph42)\
**Post date:** [June 10, 2021, 10:47pm UTC](https://forums.swift.org/t/how-swift-opaque-types-deploy-on-earlier-oss/49489/2 "2021-06-10T22:47:58Z")

</div>

The reason `some View` is so useful (or honestly vital) for SwiftUI is that it’s nearly impossible to reason about actual return types of even the most minor groups of composed `View`s. Not sure if you used a SwiftUI View as an example because it’s the opaque type we’re all the most familiar with or if it’s your actual use case, but if the latter you may be tilting at windmills.

---

<div class="post-metadata">

**Author:** ![limchihi](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@limchihi](https://forums.swift.org/u/limchihi)\
**Post date:** [June 11, 2021, 3:02am UTC](https://forums.swift.org/t/how-swift-opaque-types-deploy-on-earlier-oss/49489/4 "2021-06-11T03:02:02Z")

</div>

Actually, SwiftUI is also not available in earlier OSs. I just use those code for example.  
I also have a `protocol` that contain lot of composed type like `View` . It is very tediousness to write the actual return type. So I want to use `some` key word in develop. And use script to changed those opaque type to actual type in release build to deploy on earlier OSs

---

<div class="post-metadata">

**Author:** ![ensan-hcl](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ensan-hcl/32/15186_2.png) [@ensan-hcl](https://forums.swift.org/u/ensan-hcl)\
**Post date:** [June 11, 2021, 3:22am UTC](https://forums.swift.org/t/how-swift-opaque-types-deploy-on-earlier-oss/49489/5 "2021-06-11T03:22:39Z")

</div>

If it isn't important that the type is 'opaque', maybe 'placeholder type' is more suitable which is proposed in SE-0315. If this proposal is accepted and introduced, you would be able to write complex type more simpler. Because it is only a compiler feature, there should be no restriction to use for earlier OSs

> <https://github.com/apple/swift-evolution/blob/main/proposals/0315-placeholder-types.md>

But I don't know if it would be included in Swift5.5, maybe takes some time... 😢

* * *

You would have some workaround. In this way, you can add simple name for a complex type, without explicitly write it.

```nohighlight
protocol Some {
    associatedtype SomeType
    static var _someTypeValue: SomeType { get }
}

struct A: Some {
    // you don't have to write explicitly `SomeType` because it is inferred
    static let _someTypeValue = { 
         // process to create value of complex type
         let value = 42
         return value
    } ()
    // you can use the type here
    func use(_ value: SomeType) {}
}

```

---

<div class="post-metadata">

**Author:** ![odmir](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/odmir/32/4784_2.png) [@odmir](https://forums.swift.org/u/odmir)\
**Post date:** [June 14, 2021, 3:50pm UTC](https://forums.swift.org/t/how-swift-opaque-types-deploy-on-earlier-oss/49489/6 "2021-06-14T15:50:59Z")

</div>

I feel like the OP is being misunderstood. I don't think they are looking for an alternative to opaque types. They want to keep using opaque types but want to know if there is some way to back-port to earlier swift versions by using, for example, a tool/script that does a code transformation on the swift source files by replacing `some Type` with the actual underlying type, thus not requiring compiler support for opaque types.

@limchihi is this a good paraphrasing of what you meant?
