Filter and sort swift array
问题 I have a swift array which I want to filter, here is the array let array = [apple,workshops,shopping,sports,parties,pantry,pen] I want to filter the array in such a way that the items beginning with the search string to appear before items that just contain the search string So when i search for example p, then the results should be in some way let array = [parties,pantry,pen,apple,workshops,shopping,sports] I tried this tagSearchResults = tagSearchResults.filter({ (interestTag:InterestTag) -