xcode6 - Swift Generics Console Output -
after enable class inside playground losing console output written above class. wrong ? , weirdly showing error 'expected pattern' @ switch statement sometime , later error goes away
class cart<t> { var customername: string var customeremail: string var items: [t] var itemcount: int { return items.count } var promocode: string? = nil init(customername: string, customeremail: string){ self.customername = customername self.customeremail = customeremail items = [t]() } func add (item: t) -> () { items.append(item) } func clear () -> () { items.removeall(keepcapacity: false) } func remove (position: int) -> () { items.removeatindex(position - 1) } func getpromocodedisplay () -> (string) { if let x = promocode { return "your promo code \(x)" } else { return "you not have promo code" } } func getcartstatus () -> (string) { switch itemcount { case : 0 return "you have no items in cart." case : 1...3 return "you have \(itemcount) items in cart." default : return "you awesome customer!!" } } }
you have colon (:
) in wrong place in case statements.
func getcartstatus () -> (string) { switch itemcount { case 0 : return "you have no items in cart." case 1...3 : return "you have \(itemcount) items in cart." default : return "you awesome customer!!" } }
Comments
Post a Comment