私のアプリでは、オーディオを録音することができます(のように音声メモ)。録音が終了すると、ユーザからの入力を受けてレコードに名前を与え、オーディオはUITableView
に表示されます。録音されたオーディオは名前でソートされます(アルファベット順)。作成日によってソートする必要があります。最後に作成されたオーディオが最初に表示されます。私は2つの配列を使用しました -Swift - テーブルビューのセルを作成日でソート
1.recordedAudioFilesURLArray(タイプ:URL)& 2.recordedAudioFileName(タイプ:文字列)。
録音されたオーディオは、ドキュメントディレクトリに保存されます。ここに私のコードサンプルがある...
func getRecordedAudioFilesFromDocDirectory() {
let documentsUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
do {
let directoryContents = try FileManager.default.contentsOfDirectory(at: documentsUrl, includingPropertiesForKeys: nil, options: [])
recordedAudioFilesURLArray = directoryContents.filter{ $0.pathExtension == "m4a" }
} catch let error as NSError {
print(error.localizedDescription)
}
recordedAudioFileNames = recordedAudioFilesURLArray.flatMap({$0.deletingPathExtension().lastPathComponent})
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return recordedAudioFilesURLArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel?.text = recordedAudioFileNames[indexPath.row] as! NSString as String
return cell
}
あなたは、アレイ内のオーディオの日付を持っていますか?はいの場合は、日付の配列を共有します。 –
いいえ。私は持っていない –
あなたは何も持っていない場合、どのように日付の基準に並べ替えて喜んでですか? –