2016-04-10 10 views
2

の抽象オブジェクトに送信することはできませんnscoderスウィフトは、私は、コンテナアプリで辞書を作成しましたし、それを保存して、キーボード延長からそれを読んでください<a href="https://github.com/Archivus/SymSpell" rel="nofollow" title="SymSpell">SymSpell</a></p> <p>て自動補正を実装しようとしているクラスNSCoder

辞書は、私がオブジェクトにメソッドを追加しようとしましたが、私はエラー「のinit(コーダadecoderのnscoder)SWIFTがに送信することができませんしまったnSCoder

によって救われるためにシリアル化する必要がdictionaryItemオブジェクトが含まれていますクラスNSCoderの抽象オブジェクト "

required init(coder aDecoder: NSCoder) { 
    if let suggestions = aDecoder.decodeObjectForKey("suggestions") as? [Int] { 
     self.suggestions = suggestions 
    } 
     if let count = aDecoder.decodeObjectForKey("count") as? Int { 
     self.count = count 
     } 
} 
func encodeWithCoder(aCoder: NSCoder) { 
    if let count = self.count as? Int { 
     aCoder.encodeObject(count, forKey: "count") 
    } 
    if let suggestions = self.suggestions as? [Int] { 
     aCoder.encodeObject(suggestions, forKey: "suggestions") 
    } 
} 

これを修正する方法はありますか?

答えて

1
import Foundation 

class SuggestionModel: NSObject, NSCoding { 
    var suggestions: [Int]? 
    var count : Int? 

    required init(coder aDecoder: NSCoder) { 
     self.suggestions = aDecoder.decodeObjectForKey("suggestions") as? [Int] 
     self.count = aDecoder.decodeObjectForKey("count") as? Int 
     super.init() 
    } 

    func encodeWithCoder(aCoder: NSCoder) { 
     aCoder.encodeObject(self.count, forKey: "count") 
     aCoder.encodeObject(self.suggestions, forKey: "suggestions") 
    } 

    override init() { 
     super.init() 
    } 
} 
関連する問題

 関連する問題