forked from vashpan/xcode-dev-cleaner
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added utility methods for getting files date creation/modified
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
DevCleaner/Utilities/Extensions/FileManager+DateProperties.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// FileManager+DateProperties.swift | ||
// DevCleaner | ||
// | ||
// Created by Konrad Kołakowski on 09/11/2019. | ||
// Copyright © 2019 One Minute Games. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension FileManager { | ||
func dateModified(for url: URL) -> Date { | ||
guard let attrs = try? self.attributesOfItem(atPath: url.path) else { | ||
return Date.distantPast | ||
} | ||
|
||
guard let result = attrs[.modificationDate] as? Date else { | ||
return Date.distantPast | ||
} | ||
|
||
return result | ||
} | ||
|
||
func dateCreated(for url: URL) -> Date { | ||
guard let attrs = try? self.attributesOfItem(atPath: url.path) else { | ||
return Date.distantPast | ||
} | ||
|
||
guard let result = attrs[.creationDate] as? Date else { | ||
return Date.distantPast | ||
} | ||
|
||
return result | ||
} | ||
} |