-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
[Feature Request] IgnoreEncoding depends on other properties #91
Comments
Thanks for noticing this, this has been updated.
@hstdt can you give a practical use-case or example where this would be necessary? I think something like this is possible with |
@soumyamahunt In my case, many values have default value, I don't want to encode everything to a large json(this can be done by @IgnoreEncoding now). Based on this, some other properties like type or bool can also related to encoding condition, so that i want to get class itself not only value. @Codable class SomeClass {
var shouldEncodeValue1: Bool
var type: Int
@IgnoreEncoding(if: { ($0 as SomeClass).value != 1 && ($0 as SomeClass).shouldEncodeValue1 && ($0 as SomeClass).type == 0 })
@Default(1)
var value1: Int
@Default(2)
var value2: Int
@Default(3)
var value3: Int
@Default(4)
var value4: Int
...
@Default(10)
var value10: Int
} In additional, some unused property can be filtered after encode and decode. |
@hstdt can you give a real world use-case for this? I am more curious about how do you decode such fields if there encoding is dependent upon another property. A real world example would be better. |
@soumyamahunt Sorry for the late reply🥲, I was on vacation last week. I have a SwiftUI app
And It's unnecessary to encode everything to FileDocument, so self-manage conditional encoding might be a good idea with less bug. As above mentioned, unused properties can be filted. |
And after unused value filtered, default value will take effect with this pull request @Codable
public final class SomeClass2 {
public var value1: Bool
@IgnoreEncoding(if: { ($0 as SomeClass2).value1 || ($0 as SomeClass2).value2 == 0 })
@Default(0)
public var value2: Int!
} |
Is your feature request related to a problem? Please describe.
Nope
Describe the solution you'd like
Describe alternatives you've considered
Additional context
PS: It's a little bit strange that pass
true
toIgnoreEncoding(if:)
lead to encoding but not ignore.The text was updated successfully, but these errors were encountered: