ios - Thread 1:EXC_BAD_INSTRUCTION error when calling "addObjectsFromArray"method for NSMutableArray -
i have created program calculates borders of countries based on custom object being inputed function. function returns array of custom objects. keep getting error when trying add array nsmutablearray. error called "thread 1: exc_bad_instruction(code=exc_1386_invop, subcode=0x0)".
here adding code:
@iboutlet var label: uilabel! @iboutlet var imageview: uiimageview! override func viewdidload() { //afganistan afghanistan.name = "afghanistan" afghanistan.borders.addobjectsfromarray(relate(afghanistan)) label.text = string((afghanistan.borders[0] as! develop).name) }
here relate method along group dictionary:
func relate(x : develop) -> array<develop>{ var : [develop] = [] (_, value) in groups { y in value { if y.name == x.name { in value { if i.name != x.name { a.append(i) } } } } } return } //groups var groups = [ "one": [afghanistan] ]
here class of develop:
class develop : nsobject, nscoding { //shared var power : int! var name : string! var image : uiimage! var flag : uiimage! var militaryname : string! //military var experience : int! var oatc : int! var navy : int! var airforce : int! var artillery : int! //geography var borders : nsmutablearray! var cities : nsmutablearray! //biomes var biom : nsmutablearray! var continent : string! var nsew : string! //encoding section required convenience init(coder decoder: nscoder) { self.init() //shared self.power = decoder.decodeobjectforkey("power") as! int self.name = decoder.decodeobjectforkey("name") as! string self.image = decoder.decodeobjectforkey("image") as! uiimage self.flag = decoder.decodeobjectforkey("flag") as! uiimage self.militaryname = decoder.decodeobjectforkey("militaryname") as! string //military self.experience = decoder.decodeobjectforkey("experience") as! int self.oatc = decoder.decodeobjectforkey("oatc") as! int self.navy = decoder.decodeobjectforkey("navy") as! int self.airforce = decoder.decodeobjectforkey("airforce") as! int self.artillery = decoder.decodeobjectforkey("artillery") as! int //geography self.borders = decoder.decodeobjectforkey("borders") as! nsmutablearray self.cities = decoder.decodeobjectforkey("cities") as! nsmutablearray self.continent = decoder.decodeobjectforkey("continent") as! string self.nsew = decoder.decodeobjectforkey("nsew") as! string } convenience init( power: int, name: string, image: uiimage, flag: uiimage, relations: nsmutablearray, mname: string, experience: int, oatc: int, navy: int, airforce: int, artillery: int, borders: nsmutablearray, cities: nsmutablearray, biom: nsmutablearray, continent: string, nsew: string ) { self.init() //shared self.power = power self.name = name self.image = image self.flag = flag self.militaryname = mname //military self.experience = experience self.oatc = oatc self.navy = navy self.airforce = airforce self.artillery = artillery //geography self.borders = borders self.cities = cities self.biom = biom self.continent = continent self.nsew = nsew } func encodewithcoder(coder: nscoder) { //shared if let power = power { coder.encodeobject(power, forkey: "power") } if let name = name { coder.encodeobject(name, forkey: "name") } if let image = image { coder.encodeobject(image, forkey: "image") } if let flag = flag { coder.encodeobject(flag, forkey: "flag") } if let militaryname = militaryname { coder.encodeobject(militaryname, forkey: "militaryname") } //military if let experience = experience { coder.encodeobject(experience, forkey: "experience") } if let oatc = oatc { coder.encodeobject(oatc, forkey: "oatc") } if let navy = navy { coder.encodeobject(navy, forkey: "navy") } if let airforce = airforce { coder.encodeobject(airforce, forkey: "airforce") } if let artillery = artillery { coder.encodeobject(artillery, forkey: "artillery") } //geography if let borders = borders { coder.encodeobject(borders, forkey: "borders") } if let cities = cities { coder.encodeobject(cities, forkey: "cities") } if let biom = biom { coder.encodeobject(biom, forkey: "biom") } if let continent = continent { coder.encodeobject(continent, forkey: "continent") } if let nsew = nsew { coder.encodeobject(nsew, forkey: "nsew") } } }
"afghanistan" subclass of develop
Comments
Post a Comment