Created
December 31, 2021 11:50
-
-
Save cemolcay/61c2c422cf64c74c6507c1317de396d1 to your computer and use it in GitHub Desktop.
Get item with row and col from 1d array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Collection where Self.Index == Int { | |
subscript(row: Int, col: Int, colCount: Int) -> Element? { | |
let index = row * colCount + col | |
guard index >= 0, index < count else { return nil } | |
return self[index] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment