如何将NSDateComponent作为函数参数传递



如何将NSDateComponent对象或引用作为函数参数(只读(传递?以下代码在"编译"时失败,出现"使用未声明的类型'NSDateComponent'"错误:

import Foundation
class PreventativeCare {
var birthday = NSDateComponents()
func setPatientDOB(birthdate:NSDateComponent /* compile error */ ) {
birthday.day = birthdate.day
birthday.month = birthdate.month
birthday.year = birthdate.year
}
}

将NSDateComponent更正为NSDateComponents,效果良好。

看起来你刚刚错过了NSDateComponents中的s:(很容易犯错误,尤其是因为Cocoa中的复数类型很少。

最新更新