quantityType(forIdentifier:) deprecated in a future version of iOS?
Asked Answered
S

1

9

Xcode (I'm on v13.1) warns me, that quantityType(forIdentifier:) will be deprecated in a future version of iOS.

enter image description here

I thus checked in Apple's developer documentation for a hint what else to use. Surprisingly, on the documentation it is not labeled as deprecated in near future.

Which source to trust in this case? And in case quantityType(forIdentifier:) is indeed to be removed in teh future, is there already a known replacement?

Sapless answered 4/12, 2021 at 15:24 Comment(1)
Not sure why this question was voted down, so bumped it up. Saved me posting the same question!Flattery
S
11

The code completion dialog is merely reporting what you could see for yourself if you looked at the same header that it is looking at:

@available(iOS, introduced: 8.0, deprecated: 100000)
open class func quantityType(forIdentifier identifier: HKQuantityTypeIdentifier) -> HKQuantityType?

100000 means "the unknown future". There's no rush; it's only a warning.

But you might as well start updating your code now. The replacement will be this initializer:

https://developer.apple.com/documentation/healthkit/hkquantitytype/3778608-init

extension HKQuantityType {
    @available(iOS 15.0, watchOS 8.0, macOS 13.0, *)
    public convenience init(_ identifier: HKQuantityTypeIdentifier)
}
Senhor answered 4/12, 2021 at 16:35 Comment(3)
Ididn't know how to interpret 100000. Also nearly any example code in Apple's own documentation they use the 'deprecated' version. Again something lerned! Thank you ;)Sapless
For anyone just skimming answers looking for code and accidentally skipping the replacement (like me, took me 3 readings to notice it), the replacement code would be: HKQuantityType(HKQuantityTypeIdentifier) available iOS 15.Sennacherib
@vauxhall Feel free to edit my answer by adding a rewrite of the OP's code.Senhor

© 2022 - 2024 — McMap. All rights reserved.