I have one string array i.e.
["Anesthesiology", "Ayurveda", "Cardiology", "Cardiothoracic Surgery", "Clinical Microbiology and Infectious Diseases", "Cosmetology", "Critical Care Medicine", "Dental Surgery", "Dermatology", "Electrohomoepathy", "Emergency Medicine", "Endocrinology", "ENT", "Gastroenterology", "Gastrointestinal Surgery", "General Medicine", "General Surgery", "Genetics", "Gynaecology", "Gynaecology and Obstetrics", "Hematology", "Homeopathy", "Immunology", "Internal Medicine and Diabetology", "Nephrology", "Neurology", "Neurosurgery", "Nutrition and Dietetics", "Oncology", "Ophthalmology", "Orthopaedics", "Paediatrics", "Pain Management Specialist", "Pathology", "Pharmacology", "Physical Medicine", "Physiotherapy", "Plastic Surgery", "Podiatry", "Psychiatry", "Psychology", "Pulmonology", "Radiation Oncology", "Radiology", "Rheumatology", "Sexologist", "Urology", "Vascular Surgery", "Others"]
I am using search bar to search by characters in this array. I am using this code to search using search text:
for i in 0..<self.completeArray.count{
if String(self.completeArray[i].lowercased() ).contains("\(self.searchText!.lowercased())"){
outputArray.append(self.completeArray[i])
}
}
Now suppose If I am searching by character 'P' then my output is coming this:
["Electrohomoepathy", "Homeopathy", "Nephrology", "Ophthalmology", "Orthopaedics", "Paediatrics", "Pain Management Specialist", "Pathology", "Pharmacology", "Physical Medicine", "Physiotherapy", "Plastic Surgery", "Podiatry", "Psychiatry", "Psychology", "Pulmonology"]
But the expected output I want like:
["Paediatrics", "Pain Management Specialist", "Pathology", "Pharmacology", "Physical Medicine", "Physiotherapy", "Plastic Surgery", "Podiatry", "Psychiatry", "Psychology", "Pulmonology", "Electrohomoepathy", "Homeopathy", "Nephrology", "Ophthalmology", "Orthopaedics"]
So basically output array should show first all the element starts from the searchtext character.
Can anyone please help me on this? Thanks in Advance!