首页 > 解决方案 > 如何将 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
    }
}

标签: swiftfunctionparameter-passing

解决方案


将 NSDateComponent 更正为 NSDateComponents 并且效果很好。


推荐阅读