swift3 - How to filter the values of a string array in a struct object substring wise -




i want check value there in section object.this code working fine if write complete name in filtered object.i need filtered data when search test matches substring in string array

["a": ["affenpoo", "affenpug", "affenshire", "affenwich", "afghan collie", "afghan hound"], "b": ["bagle hound", "boxer"]]          struct objects {              var sectionname : string!              var sectionobjects : [string]               var sectionid:[string]!              var sectionph:[string]!              var sectionimage:[string]!                 }          var objectarray = [objects]()         var objectarrayfilter = [objects]()      objectarrayfilter = objectarray.filter({$0.sectionobjects.contains(searchbar.text!)}) 

if want filter if enter string afg in uitextfield should return 2 object "afghan collie", "afghan hound" section a, can make this.

objectarrayfilter = objectarray.flatmap {     var filterobjects = $0     filterobjects.sectionobjects = $0.sectionobjects.filter {          $0.range(of : searchbar.text!, options: .caseinsensitive) != nil     }     return filterobjects.sectionobjects.isempty ? nil : filterobjects }  

edit: struct have make not proper need make struct , make property object,id,ph , image type of string , make array of struct inside object struct.

struct subobjects {     var sectionobject: string!     var sectionid: string!     var sectionph: string!     var sectionimage: string! }  struct objects {     var sectionname : string!     var sectionobjects : [subobjects]!  } 

now filter way.

var objectarray = [objects]() var objectarrayfilter = [objects]()  objectarrayfilter = objectarray.flatmap {     var filterobjects = $0     filterobjects.sectionobjects = $0.sectionobjects.filter {          $0.sectionobject.range(of : searchbar.text!, options: .caseinsensitive) != nil     }     return filterobjects.sectionobjects.isempty ? nil : filterobjects } 




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 -