Skip to content

VWT functions and when to use them #48

Answered by Azoy
NSExceptional asked this question in Q&A
Discussion options

You must be logged in to vote

The idea of the VWT functions is that they do the necessary retain/releases for us, so we don't need to do any of that. initialize will make an invalid destination valid, and assign will take a valid destination and make it a copy/will take the value from the source. The original value in destination before the assign will do whatever cleanup is required in the VWT function.

  1. I would model your function like so:
extension StructMetadata {
    func createInstance(props: [String: Any] = [:]) -> Any {
        var box = AnyExistentialContainer(metadata: self)

        for (i, record) in descriptor.fields.records.enumerated() {
            guard let value = props[record.name] else {

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by NSExceptional
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants