Jacob
Jacob

Reputation: 422

Swift: how to avoid performing versions checks

I am building a Swift library. In my library, I define a struct which contains a DateInterval.

struct A {
    let date = DateInterval()
}

However, when attempting to build my library, I receive the following error:

'DateInterval' is only available on OS X 10.12 or newer'

So I added an @available(OSX 10.12, *) attribute to the struct.

The problem is now, whenever I create an instance of the struct, I am forced to perform a version check:

if #available(OSX 10.12, *) {
    let foo = A()
} else {
    // Fallback on earlier versions
}

I do not need my library to run on versions of macOS prior to 10.12; is there any way to indicate this to the compiler so that I do not have to perform cumbersome version checks each time I use this struct?

Upvotes: 2

Views: 604

Answers (1)

user3151675
user3151675

Reputation: 58019

You should change the deployment target of your library to macOS 10.12 inside your project's settings.

Deployment Target changed to 10.12

Upvotes: 3

Related Questions