I have and app with 2 custom data structures, 1 named PaxData, the other ManifestData, basically ManifestData contains an array of PaxData.
Now this was all working fine, I then implemented my NSCoding, to have permanent storage. I Added it to my PaxData and my ManifestData file. Then I tried it on simulator with iPhone 4S, worked very well. Then tried with iPad Air... got a crash here :
aCoder.encodeObject(manifestPax, forKey: PropertyKey.manifestPaxKey)
My error : Thread 1: EXC_BAD_ACCESS(code=EXC_I386_GPFLT)
Now my manifestPax is = to [PaxData]
after the crash I started digging, trying to find a solution, I eventually figured out that my app was always crashing on a 64 bit device, every time I run it on a Non-64 bits (4s-5-iPad 2) it works !
So now, I'm out of ideas... any help would be appreciated
Here's a little bit more of my ManifestData.swift file :
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)
}
EDIT : Here's 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)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.