@@ -69,7 +69,7 @@ extension DiskStorage: StorageAware {
6969 let expiry = expiry ?? config. expiry
7070 let data = try DataSerializer . serialize ( object: object)
7171 let filePath = makeFilePath ( for: key)
72- fileManager. createFile ( atPath: filePath, contents: data, attributes: nil )
72+ _ = fileManager. createFile ( atPath: filePath, contents: data, attributes: nil )
7373 try fileManager. setAttributes ( [ . modificationDate: expiry. date] , ofItemAtPath: filePath)
7474 }
7575
@@ -104,18 +104,18 @@ extension DiskStorage: StorageAware {
104104 }
105105
106106 for url in urlArray {
107- let resourceValues = try ( url as NSURL ) . resourceValues ( forKeys: resourceKeys)
108- guard ( resourceValues [ . isDirectoryKey ] as? NSNumber ) ? . boolValue == false else {
107+ let resourceValues = try url. resourceValues ( forKeys: Set ( resourceKeys) )
108+ guard resourceValues. isDirectory != true else {
109109 continue
110110 }
111111
112- if let expiryDate = resourceValues [ . contentModificationDateKey ] as? Date , expiryDate. inThePast {
112+ if let expiryDate = resourceValues. contentModificationDate , expiryDate. inThePast {
113113 filesToDelete. append ( url)
114114 continue
115115 }
116116
117- if let fileSize = resourceValues [ . totalFileAllocatedSizeKey ] as? NSNumber {
118- totalSize += fileSize. uintValue
117+ if let fileSize = resourceValues. totalFileAllocatedSize {
118+ totalSize += UInt ( fileSize)
119119 resourceObjects. append ( ( url: url, resourceValues: resourceValues) )
120120 }
121121 }
@@ -135,12 +135,12 @@ extension DiskStorage {
135135 Sets attributes on the disk cache folder.
136136 - Parameter attributes: Directory attributes
137137 */
138- func setDirectoryAttributes( _ attributes: [ FileAttributeKey : Any ] ) throws {
138+ func setDirectoryAttributes( _ attributes: [ FileAttributeKey : Any ] ) throws {
139139 try fileManager. setAttributes ( attributes, ofItemAtPath: path)
140140 }
141141}
142142
143- typealias ResourceObject = ( url: Foundation . URL , resourceValues: [ AnyHashable : Any ] )
143+ typealias ResourceObject = ( url: Foundation . URL , resourceValues: URLResourceValues )
144144
145145extension DiskStorage {
146146 /**
@@ -166,7 +166,7 @@ extension DiskStorage {
166166 var size : UInt64 = 0
167167 let contents = try fileManager. contentsOfDirectory ( atPath: path)
168168 for pathComponent in contents {
169- let filePath = ( path as NSString ) . appendingPathComponent ( pathComponent)
169+ let filePath = NSString ( string : path ) . appendingPathComponent ( pathComponent)
170170 let attributes = try fileManager. attributesOfItem ( atPath: filePath)
171171 if let fileSize = attributes [ . size] as? UInt64 {
172172 size += fileSize
@@ -198,9 +198,8 @@ extension DiskStorage {
198198 let targetSize = config. maxSize / 2
199199
200200 let sortedFiles = objects. sorted {
201- let key = URLResourceKey . contentModificationDateKey
202- if let time1 = ( $0. resourceValues [ key] as? Date ) ? . timeIntervalSinceReferenceDate,
203- let time2 = ( $1. resourceValues [ key] as? Date ) ? . timeIntervalSinceReferenceDate {
201+ if let time1 = $0. resourceValues. contentModificationDate? . timeIntervalSinceReferenceDate,
202+ let time2 = $1. resourceValues. contentModificationDate? . timeIntervalSinceReferenceDate {
204203 return time1 > time2
205204 } else {
206205 return false
@@ -209,8 +208,8 @@ extension DiskStorage {
209208
210209 for file in sortedFiles {
211210 try fileManager. removeItem ( at: file. url)
212- if let fileSize = file. resourceValues [ URLResourceKey . totalFileAllocatedSizeKey ] as? NSNumber {
213- totalSize -= fileSize. uintValue
211+ if let fileSize = file. resourceValues. totalFileAllocatedSize {
212+ totalSize -= UInt ( fileSize)
214213 }
215214 if totalSize < targetSize {
216215 break
0 commit comments