現在RSSのアプリを作成しています
var NewDataArray = NSMutableArray() var timeArray = [String]() var URL1 = "googleAPIを使用したURL" var URL2 = "googleAPIを使用したURL" var URL3 = "googleAPIを使用したURL" var URL4 = "googleAPIを使用したURL" var isLoading : Bool = false override func viewDidLoad() { super.viewDidLoad() RSSArray() } func RSSArray() { getRSS() getRSS0() getRSS1() getRSS2() } func getRSS() { if let requestURL = Foundation.URL(string: URL1) { Alamofire.request(requestURL, method: .get , parameters: nil).responseJSON { response in if response.result.isSuccess { let jsonDic = response.result.value as! NSDictionary let responseData = jsonDic["responseData"] as! NSDictionary let feed = responseData["feed"] as! NSDictionary if let entries = feed["entries"] as? NSArray { self.NewDataArray.addObjects(from: entries as! [Any]) DispatchQueue.main.async { self.myTableView.reloadData() } } } } } } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return NewDataArray.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { // 再利用するCellを取得する. let cell = tableView.dequeueReusableCell(withIdentifier: "ItemCell", for: indexPath) as! ItemCell let Newdic = NewDataArray[indexPath.row] as! NSDictionary let title = Newdic["title"] as? String let publishedDate = Newdic["publishedDate"] as? String let links = Newdic["link"] as! String let contents = Newdic["content"] as! String let timedate = self.convertDateFormat(publishedDate!) cell.title.text = title cell.time.text = timedate cell.webimage.image = UIImage(named: "") return cell } //日付を変換 func convertDateFormat(_ dateStr:String) -> String { // 引数で渡ってきた文字列をNSDateFormatterでNSDateに直します let inFormatter = DateFormatter() inFormatter.locale = Locale(identifier: "en_US_POSIX") inFormatter.dateFormat = "E, d MMM yyyy HH:mm:ss Z" let date:Date = inFormatter.date(from: dateStr)! // NSDateから指定のフォーマットの文字列に変換します let outFormatter = DateFormatter() outFormatter.dateFormat = "yyyy/MM/dd HH:mm" return outFormatter.string(from: date) } }
というコード内容なんですが、表示してみるとRSSArrayの順番に表示されます。
そこで、RSSArrayの順番ではなく日付のデータ["publishedDate"]の順番にtableviewに表示をしたいのですが、どのようにソートすれば良いのかわからないため、どうかご教授宜しくお願い致します。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/12/05 05:29
2016/12/05 06:04