我有2个自定义数据结构的应用程序,1个名为PaxData,另一个是ManifestData,基本上ManifestData包含一个PaxData数组。
现在这一切都运转正常,然后我实施了我的NSCoding,以获得永久存储。我将它添加到我的PaxData和我的ManifestData文件中。然后我在iPhone 4S的模拟器上试了一下,效果很好。然后尝试使用iPad Air ......在这里遇到了崩溃:
aCoder.encodeObject(manifestPax, forKey: PropertyKey.manifestPaxKey)
我的错误:主题1:EXC_BAD_ACCESS(代码= EXC_I386_GPFLT)
现在我的manifestPax是= [PaxData]
在崩溃后我开始挖掘,试图找到解决方案,我最终发现我的应用程序总是在64位设备上崩溃,每次我在非64位(4s-5-iPad 2)上运行)它有效!所以现在,我没有想法......任何帮助都会受到赞赏
这是我的ManifestData.swift文件的更多内容:
init?(date: NSDate, pilotName: String, acReg: String, manifestPax: [PaxData]) {
self.date = date
self.pilotName = pilotName
self.acReg = acReg
self.manifestPax = manifestPax
super.init()
if pilotName.isEmpty || acReg.isEmpty || manifestPax.isEmpty {
return nil
}
}
// MARK : NSCoding
func encodeWithCoder(aCoder: NSCoder) {
aCoder.encodeObject(date, forKey: PropertyKey.dateKey)
aCoder.encodeObject(pilotName, forKey: PropertyKey.pilotNameKey)
aCoder.encodeObject(acReg, forKey: PropertyKey.acRegKey)
aCoder.encodeObject(manifestPax, forKey: PropertyKey.manifestPaxKey)
}
required convenience init?(coder aDecoder: NSCoder) {
let date = aDecoder.decodeObjectForKey(PropertyKey.dateKey) as! NSDate
let pilotName = aDecoder.decodeObjectForKey(PropertyKey.pilotNameKey) as! String
let acReg = aDecoder.decodeObjectForKey(PropertyKey.acRegKey) as! String
let manifestPax = aDecoder.decodeObjectForKey(PropertyKey.manifestPaxKey) as! [PaxData]
self.init(date: date, pilotName: pilotName, acReg: acReg, manifestPax: manifestPax)
}
编辑:这是PaxData.swift:
init?(paxName: String, paxWeight: String, paxEmergencyName: String, paxEmergencyPhone: String, paxDestinationComments: String) {
self.paxName = paxName
self.paxWeight = paxWeight
self.paxEmergencyName = paxEmergencyName
self.paxEmergencyPhone = paxEmergencyPhone
self.paxDestinationComments = paxDestinationComments
super.init()
if paxName.isEmpty || paxWeight.isEmpty || paxEmergencyName.isEmpty || paxEmergencyPhone.isEmpty || paxDestinationComments.isEmpty {
return nil
}
}
// MARK : NSCoding
func encodeWithCoder(aCoder: NSCoder) {
aCoder.encodeObject(paxName, forKey: PropertyKey.paxNameKey)
aCoder.encodeObject(paxWeight, forKey: PropertyKey.paxWeightKey)
aCoder.encodeObject(paxEmergencyPhone, forKey: PropertyKey.paxEmergencyPhoneKey)
aCoder.encodeObject(paxEmergencyName, forKey: PropertyKey.paxEmergencyNameKey)
aCoder.encodeObject(paxDestinationComments, forKey: PropertyKey.paxDestinationCommentKey)
}
required convenience init?(coder aDecoder: NSCoder) {
let paxName = aDecoder.decodeObjectForKey(PropertyKey.paxNameKey) as! String
let paxWeight = aDecoder.decodeObjectForKey(PropertyKey.paxWeightKey) as! String
let paxEmergencyName = aDecoder.decodeObjectForKey(PropertyKey.paxEmergencyNameKey) as! String
let paxEmergencyPhone = aDecoder.decodeObjectForKey(PropertyKey.paxEmergencyPhoneKey) as! String
let paxDestinationComments = aDecoder.decodeObjectForKey(PropertyKey.paxDestinationCommentKey) as! String
self.init(paxName: paxName, paxWeight: paxWeight, paxEmergencyName: paxEmergencyName, paxEmergencyPhone: paxEmergencyPhone, paxDestinationComments: paxDestinationComments)
}