6

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?

Leo
  • 1,508
  • 13
  • 27
  • 2
    Not sure why this question was voted down, so bumped it up. Saved me posting the same question! – DavidS Dec 20 '21 at 15:36

1 Answers1

8

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)
}
vicegax
  • 4,709
  • 28
  • 37
matt
  • 515,959
  • 87
  • 875
  • 1,141
  • 1
    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 ;) – Leo Dec 05 '21 at 05:32
  • 2
    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. – vicegax Sep 29 '22 at 15:46
  • @vauxhall Feel free to edit my answer by adding a rewrite of the OP's code. – matt Sep 29 '22 at 15:51