0
인터넷에서 오랫동안 검색하고 있습니다. 그러나 사용하지 마십시오. 이를 달성하는 방법을 알려주십시오.사용자 정의 클래스를 보관 및 보관 취소 (객체 배열로 속성 가져 오기) 항상 실패했습니다.
때 보관 해제 응용 프로그램 충돌 및 나는이 메시지를 얻을 : 무슨 뜻 않습니다
Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason:
'*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (_TtCC11ArchiveTest8dogHouse3dog)
for key (NS.objects); the class may be defined in source code or a library that is not linked'
를? 누구나 도움이 될 수 있습니까? 미리 감사드립니다. ? enter image description here
내가 시도하는 경우 : 다음의 viewDidLoad에서 코드 쓰기가를 연결하는 방법 다른 작업을 수행하는 이유 이 잘 이루어집니다 enter image description here 구입이 같은 다른 코드는, 때문에
지금, 나는 종단을 인식 수업?
let ModelPath = "Model.plist".cacheDir()
class dogHouse: NSObject , NSCoding{
var dogs:[Dog]?
required init(coder aDecoder: NSCoder)
{
dogs = aDecoder.decodeObject(forKey: "dogs") as? [Dog]
super.init()
}
func encode(with aCoder: NSCoder) {
if dogs != nil{
aCoder.encode(dogs, forKey: "dogs")
}
}
class Dog: NSObject , NSCoding {
var name : String?
required init(coder aDecoder: NSCoder)
{
name = aDecoder.decodeObject(forKey: "name") as! String?
super.init()
}
func encode(with aCoder: NSCoder) {
if name != nil{
aCoder.encode(name, forKey: "name")
}
}
//ArchiveModels
func saveModel() -> Bool{
return NSKeyedArchiver.archiveRootObject(self, toFile: ICModelPath)
}
//UnArchiveModels
class func loadArchiver() -> [Dog]?{
let obj = NSKeyedUnarchiver.unarchiveObject(withFile: ICModelPath)
if obj != nil {
print(obj.debugDescription)
let model = obj as? dogHouse
return model?.dogs
}
return nil
}
}