I'm using reflection to try to make a Swift 2.0 using XCode 7 Beta JSON Serializer. I get a value that is unwrapped into an Any? type. I can check if it's an array by saying:
if value is NSArray { ... }
But that doesn't work for arrays that contains Optionals like
Array<Int?>
Array<Double?>
Etc... I have two questions:
How can I check type for Array containing any optional type as well?
How can I iterate through such an array no matter what types it contain, be it optionals or non-optionals?
See comments in this gist for context: https://gist.github.com/peheje/d69351ce2181ba349337 Seems to work all-right so far, as long as arrays doesn't contain optionals.
Alright to respond to my own question:
For checking for arrays that contains optional value, I went full verbose. It won't catch arrays filled with optional custom objects. As for casting to an array that can be iterated I used Array constructor with the arrayLiteral argument.
Funnily enough, I still can't unwrap the values with the ! operater. Always turns out as optionals.
As verbose as I could get:
Still returns: [Optional(1), nil, Optional(3), Optional(4), Optional(5), Optional(6)] For an:
It may be a bug, Swift 2.0 is still in development so yea.
Edit:
Turns out I'm not iterating more than 1 time... can't access each element. I'll leave it at this atm.