Swift Firebase UISearchController Index Out Of Range -




i have tableview lists of "places" firebase. have uisearchcontroller search through these "places". problem when tap on uisearchcontroller don't type , select "place" index out of range error. if typing or not activated uisearchcontroller, segues fine. when active , don't type when error. throws error on "let user = filteredusers[indexpath.row]"

override func prepare(for segue: uistoryboardsegue, sender: any?) {     super.prepare(for: segue, sender: sender)     if segue.identifier == "businessprofiles" {         // gotta check if we're searching         if self.searchcontroller.isactive  {             if let indexpath = tableview.indexpathforselectedrow {                 let user = filteredusers[indexpath.row]                 let controller = segue.destination as? businessprofilesviewcontroller                 controller?.otheruser = user             }         } else {             if let indexpath = tableview.indexpathforselectedrow {                 let user = usersarray[indexpath.row]                 let controller = segue.destination as? businessprofilesviewcontroller                 controller?.otheruser = user             }         }     } } 

as say, did not perform search , select place, right? if so, call empty filteredusers[indexpath.row] indexpath.row of selected row, have positive index. so, must first check if search perform, , call filteredusers[indexpath.row] this:

if !filteredusers.isempty {     if self.searchcontroller.isactive  {             if let indexpath = tableview.indexpathforselectedrow {                 let user = filteredusers[indexpath.row] 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -