現在、ファイヤーベースのストレージから画像を読み取っています。これはうまくいきます。速報でapp iosのキャッシュから画像を読み取る
// Storage.imageCache.object(forKey: post.imageUrl as NSString)
static func getImage(with url: String, completionHandler: @escaping (UIImage) ->())
{
if let image = imageCache.object(forKey: url as NSString)
{
print("CACHE: Unable to read image from CACHE ")
completionHandler(image)
}
else
{
let ref = FIRStorage.storage().reference(forURL: url)
ref.data(withMaxSize: 2 * 1024 * 1024)
{
(data, error) in
if let error = error
{
print("STORAGE: Unable to read image from storage \(error)")
}
else if let data = data
{
print("STORAGE: Image read from storage")
if let image = UIImage(data: data)
{
// Caches the image
Storage.imageCache.setObject(image, forKey: url as NSString)
completionHandler(image)
}
}
}
}
}
}
をしかし、その動作していない:
私はそれがストレージから読み出されたときにキャッシュから画像を読み込むためのキャッシュを設定しています。それはまったくうまくいかないようですが、私は 'print( "CACHE:CACHEから画像を読み取ることができません")というメッセージは表示されません。 'ストレージ」) '
これはどのように実現できますかご存知ですか?
ありがとうございました!
--- EDIT -
私のように、その後firebaseストレージから表のセルのビューで画像を呼び出す:あなたはたとえばカワセミとキャッシュ画像を実現することができます
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.feedTableView.dequeueReusableCell(withIdentifier: "MessageCell")! as UITableViewCell
let imageView = cell.viewWithTag(1) as! UIImageView
let titleLabel = cell.viewWithTag(2) as! UILabel
let linkLabel = cell.viewWithTag(3) as! UILabel
titleLabel.text = posts[indexPath.row].title
titleLabel.numberOfLines = 0
linkLabel.text = posts[indexPath.row].link
linkLabel.numberOfLines = 0
Storage.getImage(with: posts[indexPath.row].imageUrl){
postPic in
imageView.image = postPic
}
return cell
}
を役に立てば幸いプレースホルダ画像や素晴らしいですキャッシュの読み込み:https://github.com/rs/SDWebImage –