【发布时间】:2015-04-25 17:10:23
【问题描述】:
我正在使用 Apple 的 Swift 开发系统的后端部分,该部分需要处理电子邮件列表(电子邮件对象数组),我需要将我自己的属性设置为此列表,例如 allowRepeated: Bool,以及一些方法,例如如果allowRepeated 属性设置为true,则performCleanup() 删除重复条目。
我在操场上做了类似的事情,试图遵循关于扩展 NSMutableArray 类的文档说明:
class EmailList: NSMutableArray {
override var count: Int {
get {
// It seems that the line below generates a infinity loop
return NSArray(array: self).count
}
}
override func insertObject(anObject: AnyObject, atIndex index: Int) {
insertObject(anObject, atIndex: index)
}
override func removeObjectAtIndex(index: Int) {
super.removeObjectAtIndex(index)
}
override func addObject(anObject: AnyObject) {
super.addObject(anObject)
}
override func removeLastObject() {
super.removeLastObject()
}
override func replaceObjectAtIndex(index: Int, withObject anObject: AnyObject) {
super.replaceObjectAtIndex(index, withObject: anObject)
}
override func objectAtIndex(index: Int) -> AnyObject {
return super.objectAtIndex(index)
}
}
return NSArray(array: self).count 这行似乎导致了无限循环。为什么会这样?
【问题讨论】:
标签: ios swift cocoa cocoa-touch