У меня есть табличное представление, которое будет заполнять некоторые данные. Теперь мне нужно отсортировать данные табличного представления в порядке возрастания.
var SearchedobjectArray = [Objects]()
struct Objects {
var looId : String!
var looName : String
var looImageUrl:String!
var looCategoryType:String!
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if let cell = tableView.dequeueReusableCell(withIdentifier:"cell", for: indexPath) as? MyLooCell{
cell.looImage.setShowActivityIndicator(true)
cell.looImage.setIndicatorStyle(.gray)
let imageURL = SearchedobjectArray[indexPath.row].looImageUrl
if (imageURL?.isEmpty)! {
let imageUrl = self.getDefaultImageForCategory(categoryName: SearchedobjectArray[indexPath.row].looCategoryType)
cell.looImage.image = UIImage(named: imageUrl)
} else {
cell.looImage.sd_setImage(with: URL(string: SearchedobjectArray[indexPath.row].looImageUrl))
}
cell.looName.text = SearchedobjectArray[indexPath.row].looName
let looCatType = SearchedobjectArray[indexPath.row].looCategoryType
} else {
return UITableViewCell()
}
}
Я пробовал с: let array = SearchedobjectArray.sorted(by: )
Но я не уверен, как мне отсортировать эти данные в порядке возрастания a to z
. Я пробовал с другими sorted()
также, но не смог достичь.