How Swift Opaque Types deploy on earlier OSs

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

var body: some View {


var body: Text {

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

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 Views. 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.

1 Like

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

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

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

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

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) {}
1 Like
Terms of Service

Privacy Policy

Cookie Policy