无法在Swift中编码字符串数组

时间:2017-08-14 16:25:34

标签: ios arrays swift encoding

我似乎无法让我的数组被我的编码函数接受。我得到的错误是

  

“无法使用类型'的参数列表调用'encode'([String],   forKey:[String])'

var billID: [String]=[]
var billNumber: [String]=[]
var billTitle: [String]=[]
var billDescription: [String]=[]
var lastAction: [String]=[]
var lastActionDate: [String]=[]

struct stateLawData {
    static let state: String="state"
    static let lastUpdate: String="lastUpdate"
    static var billIDs: [String]=[]
    static let billNumbers: [String]=[]
    static let billDescriptions: [String]=[]
    static let billTitles: [String]=[]
    static let lastActions: [String]=[]
    static let lastActionDate: [String]=[]
}

override func encode(with aCoder: NSCoder) {
    aCoder.encode(stateAbbr, forKey: stateLawData.state)
    aCoder.encode(lastUpdateTime, forKey: stateLawData.lastUpdate)
    aCoder.encode(billID, forKey: stateLawData.billIDs)
    aCoder.encode(billNumber, forKey: stateLawData.billNumbers)
    aCoder.encode(billTitle, forKey: stateLawData.billTitles)
    aCoder.encode(billDescription, forKey: stateLawData.billDescriptions)
    aCoder.encode(lastAction, forKey: stateLawData.lastActions)
    aCoder.encode(lastActionDate, forKey: stateLawData.lastActionDate)
}

这是在UITableViewController

1 个答案:

答案 0 :(得分:1)

所有键都需要是字符串。换句话说,您的所有静态stateLawData变量都需要String,就像前两个变量一样。