When i run this code it shows nothing in my collectionView
.
My code -
class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
@IBOutlet weak var collectionView: UICollectionView!
var AllImage: [String] = []
var boolValue = false
override func viewDidLoad() {
super.viewDidLoad()
collectionView.delegate = self
collectionView.dataSource = self
downloadJson()
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
print("Found - \(AllImage.count)")
return AllImage.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell:CollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! CollectionViewCell
cell.myImage.image = UIImage(named: AllImage[indexPath.row])
return cell
}
//MARK: Image
func downloadJson(){
var access_token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjEwMjc2LCJpc3MiOiJodHRwczovL2hvbWlpdGVzdC5jby56YS9hcGkvbG9naW4iLCJpYXQiOjE1NTIxOTYwMjIsImV4cCI6MTU1NDc4ODAyMiwibmJmIjoxNTUyMTk2MDIyLCJqdGkiOiJBeTY5R0JkZDA5dWdFTDBhIn0.czpQQsC08vuTB8iGdTeEjjQUmzl6I5Cs0VQ8WeA5VaY"
let headers = ["Authorization": "Bearer "+access_token+"", "Content-Type": "application/json"]
Alamofire.request("https://homiitest.co.za/api/gallery", method: .get, parameters: nil, encoding: JSONEncoding.default, headers: headers).responseJSON { response in
if response.result.isSuccess{
print(response)
let swiftyJson = JSON(response.data!)
let productTemplate = swiftyJson["data"].array
print("hello there - \(productTemplate)")
for product in productTemplate! {
if let data = product["data"].bool {
continue
} else
{
print("I am in this block")
self.AllImage.append(product.stringValue)
}
self.collectionView!.reloadData()
}
}
}
}
}