Skip to content
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

RawValue for optional value #71

Closed
Kyle-Ye opened this issue Mar 13, 2022 · 3 comments
Closed

RawValue for optional value #71

Kyle-Ye opened this issue Mar 13, 2022 · 3 comments

Comments

@Kyle-Ye
Copy link
Contributor

Kyle-Ye commented Mar 13, 2022

The rawValue implementation is call description method

case .constant(let value): return "\(value)"
default: return ""
}

So if a TemplateValue's Value is an Optional type, it's result will surprisingly be "Optional(xx)"

A example is the following

id is UUID? type and a property in Post model
post is TemplateValue<Post> here

A { "Hello" }.id(post.id.rawValue)

This will give me "Optional(xx)" or "nil".
But what I want is "xx" or "".
However I can't do it, since I can not get a Post type or UUID? here.
All I can get is TemplateValue<Post> and TemplateValue<UUID?> and then call the rawValue method.

@Kyle-Ye
Copy link
Contributor Author

Kyle-Ye commented Mar 13, 2022

A potential solution is to support for..in loop directly in result Builder. See #72

So that we can write

Tbody {
    for post in posts {
        Tr {
           H1 { post.title }.id(post.id?.uuidString ?? "")
        }
    }
}

@mattesmohr
Copy link
Member

Not sure, what you trying to do. But the native statements are not possible at the moment. The same as we have discussed in the issue #61.

Would the statements Unwrap and Foreach help in your case?

@Kyle-Ye
Copy link
Contributor Author

Kyle-Ye commented Mar 13, 2022

Not sure, what you trying to do. But the native statements are not possible at the moment. The same as we have discussed in the issue #61.

Would the statements Unwrap and Foreach help in your case?

Got it, Unwrap is what I need. Thanks

@Kyle-Ye Kyle-Ye closed this as completed Mar 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants