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

Support struct in struct #26

Merged
merged 5 commits into from
Feb 21, 2020
Merged

Support struct in struct #26

merged 5 commits into from
Feb 21, 2020

Conversation

YusukeHosonuma
Copy link
Owner

Support struct in struct such as Dog has Owner. (and some refactoring)

@@ -3,25 +3,38 @@
func elementString<T>(_ x: T, debug: Bool, pretty: Bool) -> String {
let mirror = Mirror(reflecting: x)

let typeName = type(of: x)
let typeName = String(describing: mirror.subjectType)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bugfix: not retrieve really type name when T is Any type.

Sources/Function.swift Outdated Show resolved Hide resolved
.map { $0.indent(size: prefix.count) }
.joined(separator: ",\n")
// Optional<T>
if typeName.starts(with: "Optional<") { // TODO: better judge is exist?
Copy link
Collaborator

@sahara-ooga sahara-ooga Feb 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// TODO: better judge is exist?

As you've mentioned in slack, we can use displayStyle property of Mirror type.
https://developer.apple.com/documentation/swift/mirror/displaystyle

Suggested change
if typeName.starts(with: "Optional<") { // TODO: better judge is exist?
if case .optional = mirror.displayStyle

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggestion is not confirmed yet.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for comment, I'll change it in another PR :-)

Co-Authored-By: sahara-ooga <performa532@gmail.com>
Copy link
Collaborator

@po-miyasaka po-miyasaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙆‍♀️🙆‍♂️

@YusukeHosonuma YusukeHosonuma merged commit b325ecf into master Feb 21, 2020
@YusukeHosonuma YusukeHosonuma deleted the feature/struct-in-struct branch February 21, 2020 11:58
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.

3 participants