3

I've noticed the weirdest thing. I was playing around with NSTimer and while going through the Apple documentation, I've reached to the valid property here, and noticed that this property is available since iOS 8. This fact by its own isn't weird, but the fact the tons of stackoverflow posts from 4-6 years ago regarding NSTimer are referring to this property or suggesting to use it got me confused: Example 1, example 2, example 3 and many other.

So my question divides into 2:

  • What iOS versions really supports NSTimer valid property?
  • If I'm targeting iOS 7 and above, is it safe to use this property?

Thanks in advance.

Community
  • 1
  • 1
goldengil
  • 1,007
  • 9
  • 25
  • 1
    I am using this `NSTimer` and its `valid` property in my app targeting ios 7 and above and it is working fine – Shruti May 28 '15 at 11:58
  • if I'm not mistaken and can remember correctly I used it already in iOS4; I feel that it has been available since `NSTimer` introduced. I guess its current availability is a typo in the new docs on Apple's site. – holex May 28 '15 at 13:04

3 Answers3

3

Apple Documentation got updated for Swift, that's why it has Available in iOS 8.0 and later for some properties and methods, while they definitely were there since previous iOS versions. For instance, NSTimer was introduced in iOS 2.0. You can safely use it.

Daniil Korotin
  • 720
  • 3
  • 14
  • So in that case this is a mistake in the Apple Documentation. Should I report it? And if so, how? :) – goldengil May 28 '15 at 12:05
  • 1
    Oh, mate, you'll find it in the docs too often... I'd rather pay attention to the deprecated ones. – Daniil Korotin May 28 '15 at 12:08
  • This answer is incorrect. It has nothing to do with the documentation being updated for Swift. It has to do with the giant refactoring that Apple did that replaced many previous setter/getter methods with properties. See my answer. – rmaddy Jun 03 '15 at 14:51
2

Everyone is missing the real story. Look at the iOS 8.0 API diffs for NSTimer (and many other classes).

Apple did a huge refactor converting many APIs to use properties instead of explicit setter/getter methods.

Prior to iOS 8.0, NSTimer had a method named isValid. In iOS 8.0, Apple removed this method and added the read-only property valid (declared with a getter method name of isValid.

As a result of this change (and many like it) in iOS 8.0, the docs make a lot of APIs appear as though they were just added in iOS 8.0 even though they may have been around much longer.

The end result is the documentation is now very misleading for many properties. It's unlikely that submitting a documentation bug will do anything because this issue applies to scores of classes and hundreds of properties/methods.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • The fact that there are tones of issues such as this one in many classes and hundreds of properties/methods shouldn't be a reason to give up on it and not submitting a documentation bug. I've reported an issue on it and hopefully many will follow on similar issues, so eventually the documentation will be as accurate as it could get. Thanks for your explanation :) – goldengil Jun 03 '15 at 07:28
  • FWIW the [`isValid`](https://developer.apple.com/documentation/foundation/timer/1408249-isvalid) property is for **Swift**. For objective-c there is only the [`valid`](https://developer.apple.com/documentation/foundation/nstimer/1408249-valid?language=objc) property. Both are read-only – mfaani Sep 22 '18 at 19:46
  • @Honey In Objective-C, the `valid` property is defined such that the getter method is called `isValid`, just as I stated in my answer and just as shown in the reference documentation. – rmaddy Sep 22 '18 at 20:31
  • I don't get it. Which doc are you talking about? See https://developer.apple.com/documentation/foundation/nstimer?language=objc I don't see `isValid`. I only see `valid` – mfaani Sep 22 '18 at 20:34
  • 1
    @Honey `@property(readonly, getter=isValid) BOOL valid;`. From https://developer.apple.com/documentation/foundation/nstimer/1408249-valid?language=objc – rmaddy Sep 22 '18 at 20:34
1

I went to the NSTimer.h file and found

@property NSTimeInterval tolerance NS_AVAILABLE(10_9, 7_0);

- (void)invalidate;
@property (readonly, getter=isValid) BOOL valid;

@property (readonly, retain) id userInfo;

@end

Couldn't see the NS_AVAILABLE in front of the valid property, might be apple docs has some errors

I have also given the feedback to correct it.

enter image description here

Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184