Swift NSObject subclass get BAD_ACCESS

445 Views Asked by At

I try to persiste my object with NSCoding but i always get BAD_ACCESS ERROR To avoid multi multiple like variable, class, i put all common variable in RObject. I think i do something wrong the the init but i don't know what.

the error was thow in this function

func parseInfo(allInfos : String) -> Void {

    if let all : JSON  = JSON.parse(allInfos) as JSON? {
        if let info = all.asArray
        {
            for description in info 
            {
                var track   : RInfo = SCTracks(js: description)
                self.arrayTracks.addObject(track)
            } // Therad 1: EXC_BAD_ACCESS(code=2, address=0x27...)
        }
    }
}

The Log doesn't show any thing

My Common Class

class RObject : NSObject, NSCoding {

    var id      : Int? = 0
    var kind    : String?

    override init() { super.init() }

      init(js :JSON) {
        self.kind               = js["kind"].asString
        self.id                 = js["id"].asInt
        super.init()
    }

    required
    init(coder aDecoder: NSCoder) {
        self.id = aDecoder.decodeIntegerForKey("id") as Int
        self.kind = aDecoder.decodeObjectForKey("kind") as? String
    }

    func encodeWithCoder(aCoder: NSCoder) {
        aCoder.encodeInteger(self.id!, forKey: "id")
        aCoder.encodeObject(self.kind, forKey: "kind")
    }
}

My class Rinfo who inherits from RObject

class RInfo : RObject  {

    var title               :String?
    var uri                 :String?
    var license             :String?
    var release             :String?
    var user                :RUser!

     override init() { super.init() }

    required  init(coder: NSCoder) {
        self.title          = coder.decodeObjectForKey("title") as? String
        self.user           = coder.decodeObjectForKey("user") as RUser
        self.license        = coder.decodeObjectForKey("license") as? String
        self.uri           = coder.decodeObjectForKey("uri") as? String
        self.release       = coder.decodeObjectForKey("release") as? String
        super.init(coder: coder)
    }


    init(js :JSON)  { 
        self.user               = js(js: js["user"])
        self.title              = js["title"].asString
        self.license            = js["license"].asString
        self.uri                = js["uri"].asString
        self.release            = js["release"].asString
        super.init(js: js)
    }

    override func encodeWithCoder(encoder: NSCoder) {
        encoder.encodeObject(self.title,            forKey: "title")
        encoder.encodeObject(self.user,             forKey: "user")
        encoder.encodeObject(self.uri,              forKey: "uri")
        encoder.encodeObject(self.license,          forKey: "license")
    }   
}

Thanks for any help !

1

There are 1 best solutions below

0
On BEST ANSWER

I Solve my problem by remove variable release in RInfo. that strange