File tree 1 file changed +10
-6
lines changed
1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -17,21 +17,25 @@ class GPXFileInfo: NSObject {
17
17
/// file URL
18
18
var fileURL : URL = URL ( fileURLWithPath: " " )
19
19
20
- /// Last time the file was modified
21
20
var modifiedDate : Date {
22
- // swiftlint:disable:next force_try
23
- return try ! fileURL. resourceValues ( forKeys: [ . contentModificationDateKey] ) . contentModificationDate ?? Date . distantPast
21
+ guard let resourceValues = try ? fileURL. resourceValues ( forKeys: [ . contentModificationDateKey] ) ,
22
+ let modificationDate = resourceValues. contentModificationDate else {
23
+ return Date . distantPast // Default value if the modification date cannot be retrieved
24
+ }
25
+ return modificationDate
24
26
}
25
-
26
27
/// modified date has a time ago string (for instance: 3 days ago)
27
28
var modifiedDatetimeAgo : String {
28
29
return modifiedDate. timeAgo ( numericDates: true )
29
30
}
30
31
31
32
/// File size in bytes
32
33
var fileSize : Int {
33
- // swiftlint:disable:next force_try
34
- return try ! fileURL. resourceValues ( forKeys: [ . fileSizeKey] ) . fileSize ?? 0
34
+ guard let resourceValues = try ? fileURL. resourceValues ( forKeys: [ . fileSizeKey] ) ,
35
+ let size = resourceValues. fileSize else {
36
+ return - 1 // Default value if the file size cannot be retrieved
37
+ }
38
+ return size
35
39
}
36
40
37
41
/// File size as string in a more readable format (example: 10 KB)
You can’t perform that action at this time.
0 commit comments