ios - 快速监视可变数组的计数。

标签 ios swift nsmutablearray

嗨,我想快速监视可变数组的计数。每当我向数组添加/删除对象时,我都需要有关计数的通知。 KVO 在这里有帮助吗?如果没有,其他可能的解决方案是什么。任何帮助将不胜感激。

最佳答案

您应该能够使用KVO in Swift通过使用 dynamic 关键字。但是,对于您的特定问题,为什么不尝试使用 property observer :

var mutableArray: [AnyObject]? {
    didSet {
        println("count changed from \(oldValue.count) to \(newValue.count)")
    }
}

关于ios - 快速监视可变数组的计数。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32201591/

相关文章:

ios - Objective - c - 指针以及将数组分配给另一个数组时真正发生的事情

ios - iOS 应用程序上的一次性密码 - 建议未出现在键盘上方

ios - UIPageViewController : viewControllerBeforeViewController and viewControllerAfterViewController not called

ios - 在 Sqlite 中存储 NSMutableArray

objective-c - 在另一个函数中声明的 NSMutableArray 中添加对象

ios - 仅当当前字体大小不适合时才更改标签字体大小

ios - 如何从 VNClassificationObservation 获取对象矩形/坐标

ios - 使用 PhoneGap 和 iOS 时您首选的工作流程是什么?

swift - 从后台线程在主线程中初始化 UIView

ios - Arduino/Swift - BLE 通信 POST 和 GET