【发布时间】:2014-06-12 11:43:11
【问题描述】:
当我从 Swift 类实例化一个新对象时,我在调用中收到 Extra Argument 'frameCaptureDate' 错误。 附上代码。 发生在 Playground 和 App 中。
class SwiftFrame <NSCoding> {
var frameFilePath: NSURL
var frameCaptureDate: NSDate
init(frameFilePath: NSURL, frameCaptureDate: NSDate) {
self.frameFilePath = frameFilePath
self.frameCaptureDate = frameCaptureDate
}
init(coder: NSCoder) {
self.frameCaptureDate = coder.decodeObjectForKey("GIFFrameCaptureDate") as NSDate
self.frameFilePath = coder.decodeObjectForKey("GIFFrameFilePath") as NSURL
}
func encodeWithCoder(aCoder: NSCoder) {
aCoder.encodeObject(self.frameCaptureDate, forKey: "GIFFrameCaptureDate")
aCoder.encodeObject(self.frameFilePath, forKey: "GIFFrameFilePath")
}
}
var date = NSDate.date()
var urlstring = NSURL(string: "http://apple.com")
var sf = SwiftFrame(frameFilePath: urlstring, frameCaptureDate: date) //Error here: "Extra Argument 'frameCaptureDate' In Call"
【问题讨论】: