3 ms·
I think you're confused (or I'm mistakenly confident). @available is, indeed, when something was actually introduced. As you put it, "available to use starting
by callahad 3y ago
I think you're confused (or I'm mistakenly confident).
@available is, indeed, when something was actually introduced. As you put it, "available to use starting with this version."
@backDeployed is for when something could've worked on an earlier version, if you just copied and pasted the function body. So something that has relatively straightforward logic, doesn't change the layout of or introduce new structs, etc.
Then when you build the project, the compiler can figure out if it can just use the library's version of the function (target >= @available) or if it needs to copy over the definition itself (@backDeployed <= target < @available). But from your perspective as a consumer of the function, you can act like it's been present since the version indicated in @backDeployed.
- jagged-chisel 3y agoThe 'proposed solution': extension Toaster { @available(toasterOS 1.0, *) @backDeployed(before: toasterOS 2.0) public func makeBatchOfToast(_ breadSlices: [BreadSlice]) -> [Toast] { ... } } So it was introduced in 1.0, right? Then why do I need an annotation saying "you can use this before 2.0?" This is where I'm confused. If this example is not a mistake, the purpose of @backDeployed is not clear to me. I would have expected `@available(toasterOS 2.0, *)` indicating this was not implemented until 2.0, followed by `@backDeployed(toasterOS 1.0` indicating it's also available to this earlier version. Please correct me where I've gone wayward. My proposal would be `@available(toasterOS VersionOlderThanCurrent)` indicating this is available for use in that older version, and an optional `@developedWith(toasterOS CurrentVersion)` Edit: you say > @available is, indeed, when something was actually introduced. As you put it, "available to use starting with this version." Let me be clear in my intent: I read the linked article as saying @available is "I implemented this using version X", and I always thought it was "this will [only] work on version X (or later?)" regardless of when it was actually written. These have different meanings - that is my intent.
- suraj 3y agoIt means `makeBatchOfToast()` is available from toasterOS1.0. So if you are running toasterOS0.5 you are out of luck. If you are targeting toasterOS1.0, `@backDeployed` will ensure that the function that is copied to your binary is used. For toasterOS2.0 and above, the function provided by the linked framework will be used.
- callahad 3y agoHuh, turns out I was mistakenly confident about my own understanding after all! Suraj provides a correct explanation as a sibling comment :)