Categories

  • iOS/tech

Tags

  • iOS
  • swift
  • tech

NSCache를 사용하다보면 시스템에 의해 의도치 않게 cache가 삭제되는 경우가 있다. 이럴경우 protocol NSDiscardableContent를 이용해 cache삭제에 대한 정책을 정의할 수 있다.

import Foundation
final class LottieAnimationCacheObject: NSObject,
NSDiscardableContent {
    internal var animation: LottieAnimation?
    internal func beginContentAccess() -> Bool {
        return true
    

    internal func endContentAccess() {}

    internal func discardContentIfPossible() {
        animation = nil
    

    internal func isContentDiscarded() -> Bool {
        return animation == nil
    
}

참고

protocol NSDiscardableContent
NSCache instead of LRUCache for LottieView animation would restart from beginning after backgrounding app