The code below compiles and works in swift.
struct TestStruct {
let value: String = \"asdf\"
}
func iWantARefe
This is a feature to facilitate passing to Cocoa. Any struct can be wrapped into a SwiftValue
reference type. If you print type(of: object)
you'll see the wrapper.
I don't think there is any contract for "expecting a reference type." More importantly, while "value types" and "reference types" exist in Swift, what really matter is value and reference semantics, which are not expressible in the language. You can create value semantics in reference types and reference semantics in value types, so the Swift type system really isn't of any help in that regard.
The important point here is that you only get this unusual behavior if you explicitly request it by asking for as AnyObject
. There are very few reason to write that, and if you are, you had better know exactly what you're doing.