Tôi đang cố gắng sử dụng giao thức NSCoding trên lớp tôi đã viết nhanh, nhưng dường như không thể hiểu tại sao trình biên dịch phàn nàn rằng nó "không tuân theo giao thức NSCoding" khi tôi thực hiện các phương thức được yêu cầu:Swift: Không tuân theo giao thức NSCoding
class ServerInfo: NSObject, NSCoding {
var username = ""
var password = ""
var domain = ""
var location = ""
var serverFQDN = ""
var serverID = ""
override init() {
}
init(coder aDecoder: NSCoder!) {
self.username = aDecoder.decodeObjectForKey("username") as NSString
self.password = aDecoder.decodeObjectForKey("password") as NSString
self.domain = aDecoder.decodeObjectForKey("domain") as NSString
self.location = aDecoder.decodeObjectForKey("location") as NSString
self.serverFQDN = aDecoder.decodeObjectForKey("serverFQDN") as NSString
self.serverID = aDecoder.decodeObjectForKey("serverID") as NSString
}
func encodeWithCoder(_aCoder: NSCoder!) {
_aCoder.encodeObject(self.username, forKey: "username")
_aCoder.encodeObject(self.password, forKey: "password")
_aCoder.encodeObject(self.domain, forKey: "domain")
_aCoder.encodeObject(self.location, forKey: "location")
_aCoder.encodeObject(self.serverFQDN, forKey: "serverFQDN")
_aCoder.encodeObject(self.serverID, forKey: "serverID")
}
}
Đây có phải là lỗi hoặc tôi chỉ thiếu một cái gì đó?
"Điều này có thể đã thay đổi giữa bản phát hành beta" Có, một người muốn hét lên với Swift, "Dude, tôi có chữ ký của phương thức này từ bạn! _ Sao anh dám nói với tôi rằng giờ họ đã sai? " Nhưng tất nhiên đó là cuộc sống trong làn beta tốc độ nhanh ... – matt
@matt: Ít nhất trình biên dịch in một thông báo hợp lý ở đây, thay vì * "$% §? & Không thể chuyển thành UInt8" * :) –
Ngoại trừ một nửa thời gian tham số mà nó than phiền là sai! :)) – matt