Я хочу показать заголовок раздела как январь, февраль, март (согласно данным, полученным из API) вместо того, чтобы показывать январь, март, февраль.
Я получаю эти данные из серверного API.
wholeDic : NSDictionary = {
January = (
{
date = "20-jan-18";
subtitle = "Only four days remaining";
title = "School fees of August, 2018School fees of August, 2018";
},
{
date = "21-jan-18";
subtitle = Holi;
title = "Holiday on third march";
}
);
february = (
{
date = "20-feb-18";
subtitle = "Paricipate in this activity";
title = "Annual function will be held in feb,2018";
},
{
date = "20-12-18";
subtitle = "Holiday issue by Govt. of India";
title = "Bharat Band";
}
);
march = (
{
date = "20-feb-18";
subtitle = "Paricipate in this activity";
title = "Annual function will be held in feb,2018";
},
{
date = "20-feb-18";
subtitle = "Paricipate in this activity";
title = "Annual function will be held in feb,2018";
}
);}
Теперь я выбрал «ключ» и добавил в массив
for (key, value) in wholeDic{
sectionTitleArray.add(key)
print(sectionTitleArray)
}
, и когда я печатаю sectionTitleArray, консоль показывает January, March, February
вместо January, February, March
.
Я знаю, что словарь является неупорядоченной коллекцией, но я хочу знать, как получить ключи по порядку?
Мой источник данных и делегат UitableView
func numberOfSections(in tableView: UITableView) -> Int{
return sectionTitleArray.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let sectionTitle : String = sectionTitleArray.object(at: section) as! String
let sectiondes:NSArray = wholeDic.object(forKey: sectionTitle) as! NSArray
return sectiondes.count
}
Это мой tableView. Все работает нормально, но я хочу отобразить месяц, как ЯНВАРЬ, ФЕВРАЛЬ, МАРТ, согласно данным API.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "cell"
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! frameNboundTableViewCell
let sectionTitle : String = sectionTitleArray.object(at: indexPath.section) as! String
let contentArr : NSArray = wholeDic.object(forKey: sectionTitle) as! NSArray
let contentDic : NSDictionary = contentArr.object(at: indexPath.row) as! NSDictionary
print(contentDic)
cell.titleLbl.text = contentDic.value(forKey: "title") as? String
cell.titleLbl.numberOfLines = 0
return cell
}