I have been getting an array index out of range error and then came across this question.
Reference link
And this is the block of code.
import UIKit
import Foundation
import CoreBluetooth
EDIT 1: From what Leo suggested, so the error is gone from this block but index out of range still persists
extension Collection where Index == Int {
func get(index: Int) -> Element? {
if 0 <= index && index < count {
return self[index]
} else {
return nil
}
}
}
class Sample:UIViewController{
.......
//This is where I'm sending data
func send(){
if let send1 = mybytes.get(index: 2){
byteat2 = bytefromtextbox
print(byteat2)
}
}
}
But it doesn't seem to work.
I get an error at return self[index]
in extension Collection{}
I have also tried the following,
byteat2.insert(bytefromtextbox!, at:2)
But it returns an index out of range error.
Can someone help/advice a solution?