Skip to content

Commit 0c08a41

Browse files
Merge pull request #16 from Jeff-Meadows/remove_mirror
Remove use of Mirror in Optional nil check.
2 parents ce917f4 + 2e33321 commit 0c08a41

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ struct MyType: Codable {
421421
var createdAt: Date
422422

423423
@OptionalCoding<SecondsSince1970DateCoding>
424-
var updatedAt: Date
424+
var updatedAt: Date?
425425
}
426426
```
427427

Sources/CodableWrappers/Core/OptionalWrappers.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ extension KeyedEncodingContainer {
3131
// Used to make make sure OptionalCodingWrappers encode no value when it's wrappedValue is nil.
3232
public mutating func encode<T>(_ value: T, forKey key: KeyedEncodingContainer<K>.Key) throws where T: Encodable, T: OptionalEncodingWrapper {
3333

34-
// Currently uses Mirror...this should really be avoided, but I'm not sure there's another way to do it cleanly/safely.
35-
let mirror = Mirror(reflecting: value.wrappedValue)
36-
guard mirror.displayStyle != .optional || !mirror.children.isEmpty else {
34+
if case Optional<Any>.none = value.wrappedValue as Any {
3735
return
3836
}
3937

0 commit comments

Comments
 (0)