【问题标题】:Error with call site when instantiating Swift class实例化 Swift 类时调用站点出错
【发布时间】: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"

【问题讨论】:

    标签: ios swift


    【解决方案1】:

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

    class SwiftFrame: NSCoding {
        // stuff
    }
    

    【讨论】:

    • 是的!你是对的,它检测你是指我现在记得的超类还是协议......非常感谢!将尽快标记为答案,让我...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-02
    • 2015-04-30
    • 2016-06-01
    • 2021-08-24
    • 1970-01-01
    • 1970-01-01
    • 2020-09-20
    相关资源
    最近更新 更多