File tree Expand file tree Collapse file tree
Samples/iOS-Swift/iOS-Swift Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,10 +2,6 @@ import Foundation
22@_spi ( Private) import Sentry
33import UIKit
44
5- extension Array {
6- subscript( safe index: Int ) -> Element ? { indices. contains ( index) ? self [ index] : nil }
7- }
8-
95class 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. \n Line 2 of the text. \n Timestamp: \( 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
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments