0
在Playground中啓用此類後,我失去了寫在這個類上面的所有控制檯輸出。這有什麼問題?和古怪它顯示在switch語句「預期模式」的錯誤有時和後來的錯誤消失斯威夫特泛型控制檯輸出
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 is \(x)"
} else {
return "You do not have a promo code"
}
}
func getCartStatus() -> (String) {
switch itemCount {
case : 0
return "You have no items in your cart."
case : 1...3
return "You have \(itemCount) items in your cart."
default :
return "You are an awesome customer!!"
}
}
}