#37: Recursive Reference
Question
// Swift Quiz
— objc.io (@objcio) November 6, 2019
struct A {
var plus: APlus?
}
struct APlus {
var a: A?
var x = 2
}
var a: A = A()
var plus = APlus()
plus.x = 5
// What's the final value of plus.x?
Solution
Solution: Compiler Error
— objc.io (@objcio) November 7, 2019
Struct types cannot recursively reference themselves.
Enums have the same problem but can be marked as indirect. With Swift's structs, we need to add that indirection manually.https://t.co/s7500CWmAg