У меня есть UICollectionView, который использует UIImagePicker. Я хочу, чтобы файловая система создавала папку в документах и сохраняла/удаляла в ней UIImages. PhotoArray в настоящее время используется UICollectionView для добавления новых UIImages. (Я исследовал документацию по файловой системе Apple, но ее трудно понять)
@IBOutlet weak var collectionView: UICollectionView!
@IBOutlet weak var editBarButton: UIBarButtonItem!
let imagePicker = UIImagePickerController()
var photoArray: [UIImage] = []
override func viewDidLoad() {
super.viewDidLoad()
collectionView.delegate = self
collectionView.dataSource = self
imagePicker.delegate = self
}
// Button used to activate the UIImagePickerController
@IBAction func addButtonPressed(_ sender: UIBarButtonItem) {
imagePicker.allowsEditing = false
imagePicker.sourceType = .photoLibrary
present(imagePicker, animated: true)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let pickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
photoArray.append(pickedImage)
picker.dismiss(animated: true, completion: nil)
collectionView.reloadData()
}
}
// MARK: - collectionView DataSource
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return photoArray.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! Cell
cell.photoImageView.image = photoArray[indexPath.row]
return cell
}
Я нашел этот код в Интернете, но я не знаю, что выводит return documentDirectory[0].
func documentDirectory() -> String {
let documentDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory,
.userDomainMask, true)
return documentDirectory[0]
}