-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added CreationDate and Size properties to Item #65
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Gruppio these are great additions. I left one comment on size
.
Sources/Files.swift
Outdated
public private(set) lazy var creationDate: Date? = self.loadCreationDate() | ||
|
||
/// The size of the item in bytes, or `nil` if the information is not available | ||
public private(set) lazy var size: UInt64? = self.loadSize() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be preferred to expose size
as an Int
(as opposed to UInt64
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, of note, @JohnSundell's most recent article suggests that size
could be more "self-documenting" by creating a typealias
for Int
called ByteCount
to explicitly state that size
is in terms of bytes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @clayellis Great advice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay 🎉
Thanks for this @Gruppio! 😄 I'm wondering if it's worth force-unwrapping those optionals (like we do for |
Tests/FilesTests/FilesTests.swift
Outdated
let data = "1234567890".data(using: .utf8)! | ||
let fileWithContent = try folder.createFile(named: "FileWithContent") | ||
try fileWithContent.write(data: data) | ||
if let fileWithContentSize = fileWithContent.size { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general it's not a good idea to use conditionals in unit tests, as it can often end up causing false positives (if the property isn't supposed to be nil, but actually is). You can use XCTAssertEqual
with an optional, so better pass fileWithContent.size
directly instead of using an if let
🙂
Hi @JohnSundell ! My pleasure! |
@JohnSundell I've made the changes but I had to disable those 2 test for linux 😞 |
Hi!
I've added these 2 new properties to Item.
These new properties are optional because on some Linux systems may not be available