4
votes

In iOS 8, Apple introduces var accessibilityElements: [Any]?.

  • func accessibilityElementCount() -> Int
  • func accessibilityElement(at: Int) -> Any?
  • func index(ofAccessibilityElement: Any) -> Int

What's the difference between them? Is the priority of var accessibilityElements: [Any]? higher than the old methods?

Reference: https://developer.apple.com/documentation/uikit/accessibility/uiaccessibilitycontainer

1

1 Answers

1
votes

I don't have concrete proof for you, but my suggestion is you use the new one : var accessibilityElements: [Any]? if you are targeting iOS 8 and above.

Why? Because I believe the old methods would be deprecated in the future. They are redundant. Accessing it via an array would also allow you to do the other methods because they are built in the Array.

Tl:dr The API does not state any difference between them, so go with the newer one.