Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Swift error some return types are only available on macOS 10.12

I have the following code however I am getting an error

some return types are only available in macOS 10.15.0 or newer

I do not want to add the @available on this. Is there a another way that I can restructure the follow code

public extension Action
{
    static var none: some Action { NoAction() }
    
    // -------------------------------------
    /** other code below
}

I have a struct in a different file
noAction.swift

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

public struct NoAction: Action
{
    public init() { }
    
    // -------------------------------------
    public var keyEquivalent: KeyEquivalent?
    {
        get { nil }
        set { }
    }
    
//other code same structure
}

>Solution :

As it notes, some return types are only available in macOS 10.15.0 or newer. So if you want to run on older versions, you cannot return a "some" type (i.e. an opaque type). You’ll need to return a non-opaque type:

static var none: NoAction { NoAction() }

Alternately, you could return an existential type (i.e. a box around the protocol). That introduces some limitations on how it’s used, but may match your needs:

static var none: Action { NoAction() }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading