2

Apple has changed the Swift reflection in XCode 7 beta 5. The global reflect() function is gone, and you'll have to do this:

let mirror = Mirror(reflecting: object)

It gives more or less the same information in a nicer way (no more .1 og .2 for propertyname and value). But I can't find a way to explore if the mirrored item is an instance of a class. The older implementation you could check the following:

reflectedProperty.1.objectIdentifier != nil || reflectedProperty.1.count > 0

But objectIdentifier seems to be gone and the count is always 2 regardless of type.

Help anyone?

Peheje
  • 12,542
  • 1
  • 21
  • 30

2 Answers2

2

Ok so I found a workaround. I was iterating over mirror.children.enumerate() which seemed to make all the properties of type String. Instead I dug into Apple preliminary documentation, and read that it could be a good idea to "upgrade" children to e.g. AnyRandomAccessCollection. Which made it possible to rely on the count of an objects children to determine if it's an object (after testing whether it's an array)

Currently I have a functioning Swift class to JSON Serializer working here on this gist if you are interested in the code: https://gist.github.com/peheje/cc3618253d4f38ea4885

Peheje
  • 12,542
  • 1
  • 21
  • 30
1

I am not sure if you are looking for this, but the output for the following is "Class"

mirror.displayStyle