-
Notifications
You must be signed in to change notification settings - Fork 129
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
RUMM-987 Prepare code generation for RUM @objc models #382
RUMM-987 Prepare code generation for RUM @objc models #382
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.
that should work ✅
by adding missing `import Foundation`
.../rum-models-generator/Sources/RUMModelsGeneratorCore/Input/ObjcInterop/ObjcInteropType.swift
Outdated
Show resolved
Hide resolved
.../rum-models-generator/Sources/RUMModelsGeneratorCore/Input/ObjcInterop/ObjcInteropType.swift
Outdated
Show resolved
Hide resolved
...odels-generator/Sources/RUMModelsGeneratorCore/Input/ObjcInterop/ObjcInteropTypeReader.swift
Show resolved
Hide resolved
...odels-generator/Sources/RUMModelsGeneratorCore/Input/ObjcInterop/ObjcInteropTypeReader.swift
Show resolved
Hide resolved
...odels-generator/Sources/RUMModelsGeneratorCore/Input/ObjcInterop/ObjcInteropTypeReader.swift
Show resolved
Hide resolved
...odels-generator/Sources/RUMModelsGeneratorCore/Input/ObjcInterop/ObjcInteropTypeReader.swift
Show resolved
Hide resolved
tools/rum-models-generator/Sources/RUMModelsGeneratorCore/Output/Printing/SwiftPrinter.swift
Show resolved
Hide resolved
tools/rum-models-generator/Tests/rum-models-generator-coreTests/RUMModelsGeneratorTests.swift
Show resolved
Hide resolved
...m-models-generator/Tests/rum-models-generator-coreTests/Output/ObjcInteropPrinterTests.swift
Show resolved
Hide resolved
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.
As discussed there is some potential confusion between Reader
/Transformer
to clarify/refactor, but that will fit better in a follow-up PR. Looks great anyway!
What and why?
📦 This PR updates the
rum-models-generator
tool to generate@objc
RUM data models. This is required to further expose scrubbing API inDatadogObjc
as it was done for Swift (#367).How?
I leveraged the existing architecture of
rum-models-generator
:read → transform → print
by implementing another
Printer
:read → transform → SwiftPrinter
read → transform → ObjcInteropPrinter
The
SwiftType
schema generated and transformed for Swift code generation is now used byObjcInteropReader
to generateObjcInteropType
schema. The schema is later passed to theObjcInteropPrinter
for printing the actual code.Swift / Obj-c interoperability for RUM
@objc
interoperability is done by wrapping Swiftstructs
in@objc
classes and exposing Swiftenums
as@objc enum
.Simple example can be illustrated as:
Nested
structs
are managed by transitive@objc classes
:Code Reviewing
🙏 Please, carefully follow all the code snippets generated in
ObjcInteropPrinterTests
. They showcase solutions to all edge-cases and Swift <> Obj-c interoperability limitations that I struggled with. Better alternatives are welcome 🙌.Especially, I want to draw your attention to two things:
1/ Some Swift value types are incompatible with
@objc
Types like
Int64
,Bool?
orEnumeration?
cannot be directly exposed. Numeric types are represented asNSNumber
. Optionalenums
required adding extracase none
to representnil
.2/ Building key-paths to optional properties requires
!
unwrappingSome property wrappers in transitive
@objc
classes require force unwrapping of the Swiftstruct's
key path, e.g.:The safety of this construct is guaranteed by the
!= nil
check in the property wrapper providing the access toDDFooBar
:Coming in next PRs:
Next PRs will focus on:
@objc
RUM models validation,DatadogObjc
.Review checklist