I'm trying to create a math expression using an Enumeration in Swift. This enumeration can be a constant, with an associated value of type ComplexNumber (a simple struct). It also can be a square root expression, with a recursive associated value. For example, I want to be able to store sqrt(sqrt(1+2i)) in an enum.
enum Expression {
case Sqrt(Expression)
case Constant(ComplexNumber)
}
Xcode (6 beta 2) crashes immediately. What's the problem? From what I read in the Swift guide about associated values, this should work.
Now possible with Swift 2.0 since beta 4. Examples taken from release notes:
enum List<T> {
case Nil
indirect case Cons(head: T, tail: List<T>)
}
indirect enum Tree<T> {
case Leaf(T)
case Branch(left: Tree<T>, right: Tree<T>)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.