Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-8485] Sequence implementation for IndexPath's indices is broken #3650

Closed
swift-ci opened this issue Aug 7, 2018 · 2 comments
Closed

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Aug 7, 2018

Previous ID SR-8485
Radar None
Original Reporter sstigler (JIRA User)
Type Bug
Status Resolved
Resolution Invalid
Environment

Xcode 9.4 (9F1027a)

Additional Detail from JIRA
Votes 1
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: 6d355f9ad3fc066fb22e7c3e35492a79

Issue Description:

Steps to Reproduce:

Paste the following code into a playground:

import Foundation

let indexPath = IndexPath(indexes: [1,3])

var indices = [Int]()
for index in indexPath.indices {
    indices.append(index)
}

print(indices)

Actual Results:
"[0, 1]" is printed

Expected Results:
"[1,3]" would be printed.

@belkadan
Copy link

belkadan commented Aug 8, 2018

The "indices" of an IndexPath refers to what you can subscript it with, not its contents.

import Foundation

let indexPath = IndexPath(indexes: [1,3])
print(indexPath[1])

IndexPath itself is a Sequence (via Collection) which can give you the answer you expect:

import Foundation

let indexPath = IndexPath(indexes: [1,3])

var indices = [Int]()
for index in indexPath {
    indices.append(index)
}

print(indices)

@swift-ci
Copy link
Contributor Author

swift-ci commented Aug 8, 2018

Comment by Sam Stigler (JIRA)

Ah, okay. That makes more sense; thanks for clearing it up for me. indices makes it sound like those are its component (and possibly non-contiguous) indices, but I see that name is required for IndexPath's RandomAccessCollection conformance.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants