안드로이드 webview에서 클리어 캐시를 만들고난 후
ios에서도 적용하기 위해 코들 보았는데
URLCache.shared.removeAllCachedResponses()
URLCache.shared.diskCapacity = 0
URLCache.shared.memoryCapacity = 0
이런식으로 이미 캐시를 날리고 있었다.
하지만 마찬가지로 캐시가 덜 날라가는 느낌이라
캐시 디렉토리도 날려버리기로 하고 코드를 작성하였다.
func clearCache(){
let cacheURL = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!
let fileManager = FileManager.default
do {
// Get the directory contents urls (including subfolders urls)
let directoryContents = try FileManager.default.contentsOfDirectory( at: cacheURL, includingPropertiesForKeys: nil, options: [])
for file in directoryContents {
do {
try fileManager.removeItem(at: file)
}
catch let error as NSError {
debugPrint("Ooops! Something went wrong: \(error)")
}
}
} catch let error as NSError {
print(error.localizedDescription)
}
}
이렇게 만든후 특정버튼을 누를시 clearCache() 를 날려주니
확실히 눈에띄게 앱 메모리가 줄어드는것을 확인 할 수 있었다.
'공부 > IOS swift' 카테고리의 다른 글
(COCOAPODS) pod install unable to find a specification for '[name] (~>x.x.x)' (0) | 2018.07.15 |
---|---|
xcode simulator screenshot size (0) | 2018.05.18 |
(IOS) 공유하기 기능 ipad 적용 (0) | 2017.12.24 |
(IOS) launchscreen cache (2) | 2017.12.24 |
(swift) '++' is deprecated: it wiil be removed in Swift 3 (0) | 2016.09.18 |