var imgArray = [UIImage]();
var CDataArray = NSMutableArray();
for img in imgArray{
let data : NSData = NSData(data: UIImagePNGRepresentation(img))
CDataArray.addObject(data);
}
//convert the Array to NSData
//you can save this in core data
var coreDataObject = NSKeyedArchiver.archivedDataWithRootObject(CDataArray);
//extract:
if let mySavedData = NSKeyedUnarchiver.unarchiveObjectWithData(coreDataObject) as? NSArray{
//extract data..
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
let images = NSKeyedUnarchiver.unarchiveObject(with: recipe.imageRecipe! as Data) as! NSMutableArray
return images.count
}func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Collection_cell", for: indexPath) as! CollectionViewCell
let images = NSKeyedUnarchiver.unarchiveObject(with: recipe.imageRecipe! as Data) as! NSMutableArray
let img = UIImage(data: images[indexPath.row] as! Data)!
cell.recipeImageView.image = img
return cell
}
ImageCache.default.retrieveImage(forKey: "key_for_image", options: nil) {
image, cacheType in
if let image = image {
print("Get image \(image), cacheType: \(cacheType).")
//In this code snippet, the `cacheType` is .disk
} else {
print("Not exist in cache.")
}
}