How does `@available(obsoleted)` work?

I was experimenting with @available to get a sense of how it works. I started with:

@available(OSX, introduced: 13.0)
struct Foo { }

func foo() {
  _ = Foo()
}

and easy enough, when I tried to compile it to a mac target, I get an error:

'Foo' is only available in macOS 13.0 or newer

with a fix-it to add #available. This is pretty much what I expect.

However, when I tried the same code with deprecated: 13.0 and obsoleted: 13.0, there is no error/warning. I set the platforms on Package.swift to platforms: [.macOS(.v10_14)], so it's well out-of-range.

Is it expected to not produce any warning? What does the compiler pick up on when figuring out if something needs to be behind #available?

I'm confused about your question. If an API is to be deprecated in macOS 13, then of course there are no warnings when you compile it for macOS 10.14?

3 Likes

Don’t feel bad. I forget the 10. in front all the time too.

4 Likes

Ok, I was too restless to wait for 13.0 announcement in 2052 :joy:.

4 Likes
Terms of Service

Privacy Policy

Cookie Policy