Skip to content

Commit cd8e4f0

Browse files
committed
review-comment: Move array extension to dedicated Tools folder
https://github.com/getsentry/sentry-cocoa/pull/7581/changes#r2882733913
1 parent 2abb09c commit cd8e4f0

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

Samples/iOS-Swift/iOS-Swift/NetworkTestingViewController.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ import Foundation
22
@_spi(Private) import Sentry
33
import UIKit
44

5-
extension Array {
6-
subscript(safe index: Int) -> Element? { indices.contains(index) ? self[index] : nil }
7-
}
8-
95
class NetworkTestingViewController: UIViewController {
106

117
// MARK: - UI Elements
@@ -70,7 +66,7 @@ class NetworkTestingViewController: UIViewController {
7066
} else {
7167
request.httpBody = (requestBodyTextView.text ?? "").data(using: .utf8)
7268
}
73-
request.setValue(contentTypes[safe: index] ?? "text/plain", forHTTPHeaderField: "Content-Type")
69+
request.setValue(contentTypes.element(at: index) ?? "text/plain", forHTTPHeaderField: "Content-Type")
7470
}
7571

7672
private func updateBodyTextViewForType(_ index: Int) {
@@ -80,7 +76,7 @@ class NetworkTestingViewController: UIViewController {
8076
"This is a plain text body for testing network capture.\nLine 2 of the text.\nTimestamp: \(Date())",
8177
"// Binary data will be generated automatically\n// Size: ~10KB of random bytes"
8278
]
83-
requestBodyTextView.text = bodies[safe: index] ?? ""
79+
requestBodyTextView.text = bodies.element(at: index) ?? ""
8480
requestBodyTextView.isEditable = index != 3
8581
}
8682

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Foundation
2+
3+
extension Array {
4+
/// Returns element at the given index if it's within bounds, otherwise returns nil.
5+
func element(at index: Int) -> Element? {
6+
guard index >= 0, index < count else {
7+
return nil
8+
}
9+
return self[index]
10+
}
11+
}

0 commit comments

Comments
 (0)