Just for fun I tested out, if such a function is actually working:
func exampleFunction() -> Any {
struct Example {
let x: Int
}
let example = Example(x: 2)
return example
}
And surprisingly it is. My question is now: Is it able to access for example x
from the function? Of course this doesn't work:
let example = exampleFunction()
print(example.x)
//Error: Value of type 'Any' has no member 'x'
It has to be type casted first, but with which type?
let example = exampleFunction()
print((example as! Example).x)
//Of course error: Use of undeclared type 'Example'
print((example as! /* What to use here? */).x)
Surprisingly print(type(of: example))
prints the correct string Example