【发布时间】:2015-08-07 23:05:03
【问题描述】:
我已经创建了一个这样的自定义 UITextField
import Foundation
import UIKit
class NoZeroTextField: UITextField, UITextFieldDelegate {
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.delegate = self
}
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
if (string == "0" ) {
//ignore input
return false
}
return true
}
}
我正在尝试为该类编写单元测试,但问题在于将 NSCoder 实例传递给构造函数。我无法实例化它或将其设置为零。如何对这个类进行单元测试?
【问题讨论】:
-
你的textField方法是内部的,不用NSCoder构造函数直接测试一下?
-
“直接”是什么意思?
标签: ios swift unit-testing xcode7 xcode7-beta5