Last active
November 2, 2019 10:27
-
-
Save sgr-ksmt/96229dd8ebd5fc17755fdbd0853e805d to your computer and use it in GitHub Desktop.
PropertyWrapper+Codable crash.
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
struct ModelA: Codable { | |
@Wrap<ModelA> var a: String? = "foobar" | |
} |
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
struct ModelB: Codable { | |
@Wrap<ModelB> var b: String? // doesn't work if inital value given (e.g. `@Wrap<ModelB> var b: String? = "foobar"`) | |
} |
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
struct Test { | |
func test() { | |
_ = try? JSONEncoder().encode(ModelA()) // doesn't work. | |
_ = try? JSONEncoder().encode(ModelB()) // works. | |
} | |
} |
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
@propertyWrapper | |
struct Wrap<T>: Codable where T: Codable { | |
private var path: String? | |
init(wrappedValue path: String?) { | |
self.path = path | |
} | |
var wrappedValue: String? { | |
get { path } | |
set { path = newValue} | |
} | |
var projectedValue: Self { | |
self | |
} | |
} |
Author
sgr-ksmt
commented
Nov 2, 2019
- Compile Error will cause if define each class to different files.
- Compile Error will not cause if define each class to same file.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment