一步一迹 2016-04-18 08:00 采纳率: 0%
浏览 1552
已结题

swift 类中使用泛型报错

小弟刚刚学swift些了一段代码但是运行时报错感觉很迷惑,希望有人可以解惑什么地方错了:

 class Pushpop<T> {
    var items = [T]()
    func push(item:T) {
        items.append(item)
    }
    func pop() {
        items.removeLast()
    }

}
var stack = Pushpop<String>()
stack.push("things")
stack.push("other")
stack.pop()
stack.push("ss")
for item in stack.items {
    print(item)
}

图片说明

  • 写回答

3条回答 默认 最新

  • magicioney 2016-04-18 08:35
    关注

    你在哪里运行的?我在playground上跑了一遍,无误。

    评论

报告相同问题?