当我从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"

最佳答案

看起来该错误是类声明中语法错误的副作用。在Swift中,这就是您指定协议一致性的方式。

class SwiftFrame: NSCoding {
    // stuff
}

关于ios - 实例化Swift类时调用站点出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24183485/

10-09 04:21