Quite new to programming in Swift, what is the reason to my error and how can I fix it? Many thanks.
import UIKit
import Photos
class PhotosViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource , UICollectionViewDelegateFlowLayout, UIImagePickerControllerDelegate, UINavigationControllerDelegate
{
@IBOutlet weak var myCollectionView: UICollectionView!
var imagesArray = [UIImage]()
override func viewDidLoad(){
super.viewDidLoad()
myCollectionView.delegate = self
myCollectionView.dataSource = self
}
@IBAction func addPhoto(_ sender: AnyObject) {
let picker:UIImagePickerController = UIImagePickerController()
picker.sourceType = .photoLibrary
picker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)!
picker.delegate = self
picker.allowsEditing = false
self.present(picker, animated: true, completion: nil)
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! cell
cell.configurecell(imagesArray[indexPath.row])
return cell
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return imagesArray.count
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let pickedimage = (info[UIImagePickerControllerOriginalImage] as? UIImage){
imagesArray = [pickedimage,pickedimage,pickedimage]//Will store three selected images in your array
myCollectionView.reloadData()
}
dismiss(animated: true, completion: nil)
}
}
Second Image


as! cell- this part is problematic, you need a type name to cast to.cellis a variable name.