Skip to content

Conversation

soumyamahunt
Copy link
Contributor

@soumyamahunt soumyamahunt commented May 20, 2025

Added support for applying common strategies (like ValueCoder) to all properties of a type using the @codable macro's commonStrategies parameter.

Features:

  • Added HelperCoderStrategy for specifying common type conversion strategies
  • Added CodableCommonStrategy for use with @codable macro
  • Added StrategyFinder to extract and apply common strategies during macro expansion
  • Added comprehensive test suite for common strategies functionality

Example usage:

@Codable(commonStrategies: [.codedBy(.valueCoder())])
struct Model {
    let int: Int      // Uses ValueCoder<Int>
    let url: URL      // Uses standard Codable (not ValueCodingStrategy)
    let string: String // Uses ValueCoder<String>
}

resolves #93, resolves #51

Copy link

codecov bot commented May 20, 2025

Codecov Report

Attention: Patch coverage is 95.95960% with 4 lines in your changes missing coverage. Please review.

Project coverage is 94.92%. Comparing base (cc973b0) to head (e013047).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
.../HelperCoders/Strategies/HelperCoderStrategy.swift 0.00% 3 Missing ⚠️
...es/MetaCodable/Codable/CodableCommonStrategy.swift 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #129      +/-   ##
==========================================
- Coverage   94.99%   94.92%   -0.07%     
==========================================
  Files         109      113       +4     
  Lines        4312     4411      +99     
==========================================
+ Hits         4096     4187      +91     
- Misses        216      224       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@soumyamahunt soumyamahunt merged commit ab61565 into main May 21, 2025
12 of 13 checks passed
@soumyamahunt soumyamahunt deleted the feat/common-strategies branch May 21, 2025 11:52
@zy19890102
Copy link

When the attribute value is optional, the strategy is invalid.

@zy19890102
Copy link

Directly applying @codedby(ValueCoder()) to the attribute works correctly.

@zy19890102
Copy link

When the struct conforms to the Codable protocol, macro code generation fails.

@soumyamahunt
Copy link
Contributor Author

@zy19890102 can you create a issue for this? I don't think there is optional type support for this yet but it should be a small change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Support convert JSON fields to the types of my Swift objects automatically, without me having to manually add @CodedBy.

2 participants