ios8 - Custom map view crashing in initWithCoder in swift -


i have uitableviewcell, has map view subview. created custom class handles actions adding annotations, delegates etc , named customemap.swift.

after changed class name of map view customemap in cell xib, app crashes times @ initwithcoder method of customemap because have not implemented method. later added method below:

import uikit import mapkit   protocol customemapdelegate{     func annotationclickevent(info:nsdictionary?) }  class customemap: mkmapview,mkmapviewdelegate,cllocationmanagerdelegate {      var locationmanager:cllocationmanager?     var delegate1:customemapdelegate?     var tap:uitapgesturerecognizer?      required init(coder adecoder: nscoder) {         super.init(coder: adecoder)     }      override func awakefromnib()     {         if cllocationmanager.authorizationstatus() == clauthorizationstatus.authorizedalways {             self.showsuserlocation = true;         }         else         {             locationmanager = cllocationmanager()             locationmanager?.delegate = self;             if locationmanager!.respondstoselector("requestalwaysauthorization")             {                 locationmanager?.requestalwaysauthorization()             }         }         self.delegate = self         self.userinteractionenabled = true         tap = uitapgesturerecognizer(target: self, action: "calloutaction:")     }     func locationmanager(manager: cllocationmanager!, didchangeauthorizationstatus status: clauthorizationstatus)     {         if(status == clauthorizationstatus.authorizedalways)         {             self.showsuserlocation = true;         }     }      func skiptouch()     {      }      class func createannotationfordict(temp:nsdictionary)->mypointannotation     {         var venue = temp.valueforkey("venue") as? nsdictionary         var lat = venue!.valueforkey("latitude") as! double         var lon = venue!.valueforkey("longitude") as! double         var venuename = venue!.valueforkey("name") as! string         var dealname = temp.valueforkey("title") as? string          var coord:cllocationcoordinate2d = cllocationcoordinate2d(latitude: 0, longitude: 0)         coord.latitude = lat         coord.longitude = lon         var point = mypointannotation()         point.userinfo = temp         point.coordinate = coord         point.title = dealname         point.subtitle = venuename         return point     }      func mapview(mapview: mkmapview!, viewforannotation annotation: mkannotation!) -> mkannotationview!     {         if annotation mkuserlocation {             return nil         }          let reuseid = "pin"          var pinview = mapview.dequeuereusableannotationviewwithidentifier(reuseid) as? mkpinannotationview         if pinview == nil {             pinview = mkpinannotationview(annotation: annotation, reuseidentifier: reuseid)             pinview!.canshowcallout = true             pinview!.animatesdrop = true             pinview!.pincolor = .red              var assimg = uiimageview(image: uiimage(named: "r_arrow_g"))             assimg.frame = cgrectmake(0, 0, 16, 16)             assimg.contentmode = uiviewcontentmode.scaleaspectfit             pinview!.rightcalloutaccessoryview = assimg          }         else {             pinview!.annotation = annotation         }         return pinview     }     func mapview(mapview: mkmapview!, didselectannotationview view: mkannotationview!)     {         if view.annotation.iskindofclass(mkuserlocation){ return }         if let t1 = tap         {          }         else         {             tap = uitapgesturerecognizer(target: self, action: "calloutaction:")         }         view.addgesturerecognizer(tap!)     }     func mapview(mapview: mkmapview!, diddeselectannotationview view: mkannotationview!)     {         if view.annotation.iskindofclass(mkuserlocation){ return }         view.removegesturerecognizer(tap!)     }     func calloutaction(sender:uitapgesturerecognizer)     {         if(delegate1 != nil)         {             var view = sender.view as! mkannotationview             var ann = view.annotation as! mypointannotation             delegate1!.annotationclickevent(ann.userinfo)         }     }  } 

but still same issue.

crash log

crashed: com.apple.main-thread exc_bad_access kern_invalid_address @ 0x00000001        thread : crashed: com.apple.main-thread 0  libgpusupportmercury.dylib     0x2b7228fe gpus_returnnotpermittedkillclient 1  libgpusupportmercury.dylib     0x2b7233cb gpussubmitdatabuffers 2  libgpusupportmercury.dylib     0x2b723249 gldcreatecontext 3  glengine                       0x2717191b glicreatecontextwithshared 4  opengles                       0x2724dab3 -[eaglcontext initwithapi:properties:] + 406 5  opengles                       0x2724d86f -[eaglcontext initwithapi:sharedwithcompute:] + 142 6  vectorkit                      0x2fc2d58b ggl::oescontext::oescontext(ggl::gldevice*, std::__1::shared_ptr<ggl::oessharegroup>) + 530 7  vectorkit                      0x2fc2663f ggl::gldevice::createrenderer() + 110 8  vectorkit                      0x2fb46c0f -[mddisplaylayer _creategllayer] + 166 9  vectorkit                      0x2fb469af -[mddisplaylayer init] + 70 10 vectorkit                      0x2f8763b7 -[vkmapview initwithglobe:shouldrasterize:inbackground:] + 486 11 mapkit                         0x25f4937f -[mkbasicmapview initwithframe:andglobe:shouldrasterize:] + 362 12 mapkit                         0x25f7b14b -[mkmapview _commoninitfromib:gesturerecognizerhostview:showsattribution:] + 982 13 mapkit                         0x25f7bc4d -[mkmapview initwithcoder:] + 128 14 appname                        0x000ce410 @objc appname.customemap.init (appname.customemap.type)(coder : objectivec.nscoder) -> appname.customemap (customemap.swift) 15 uikit                          0x280f6611 -[uiclassswapper initwithcoder:] + 192 16 uikit                          0x281bd6ef uinibdecoderdecodeobjectforvalue + 850 17 uikit                          0x281bd38f -[uinibdecoder decodeobjectforkey:] + 334 18 uikit                          0x280f6253 -[uiruntimeconnection initwithcoder:] + 150 19 uikit                          0x281bd6ef uinibdecoderdecodeobjectforvalue + 850 20 uikit                          0x281bd645 uinibdecoderdecodeobjectforvalue + 680 21 uikit                          0x281bd38f -[uinibdecoder decodeobjectforkey:] + 334 22 uikit                          0x280f593f -[uinib instantiatewithowner:options:] + 958 23 uikit                          0x28014077 -[uiviewcontroller _loadviewfromnibnamed:bundle:] + 238 24 uikit                          0x27e52e99 -[uiviewcontroller loadview] + 92 25 uikit                          0x27d370ed -[uiviewcontroller loadviewifrequired] + 68 26 uikit                          0x27de0ed5 -[uinavigationcontroller _layoutviewcontroller:] + 32 27 uikit                          0x27de0dfd -[uinavigationcontroller _updatescrollviewfromviewcontroller:toviewcontroller:] + 228 28 uikit                          0x27de0393 -[uinavigationcontroller _starttransition:fromviewcontroller:toviewcontroller:] + 74 29 uikit                          0x27de00c3 -[uinavigationcontroller _startdeferredtransitionifneeded:] + 578 30 uikit                          0x27ddfe2d -[uinavigationcontroller __viewwilllayoutsubviews] + 44 31 uikit                          0x27ddfdc1 -[uilayoutcontainerview layoutsubviews] + 184 32 uikit                          0x27d347ff -[uiview(calayerdelegate) layoutsublayersoflayer:] + 514 33 quartzcore                     0x2775a835 -[calayer layoutsublayers] + 136 34 quartzcore                     0x2775620d ca::layer::layout_if_needed(ca::transaction*) + 360 35 quartzcore                     0x27756095 ca::layer::layout_and_display_if_needed(ca::transaction*) + 16 36 quartzcore                     0x27755a71 ca::context::commit_transaction(ca::transaction*) + 224 37 quartzcore                     0x27755875 ca::transaction::commit() + 324 38 uikit                          0x27d2cc91 _aftercacommithandler + 132 39 corefoundation                 0x247e0ffd __cfrunloop_is_calling_out_to_an_observer_callback_function__ + 20 40 corefoundation                 0x247de6bb __cfrunloopdoobservers + 278 41 corefoundation                 0x247deac3 __cfrunlooprun + 914 42 corefoundation                 0x2472c3b1 cfrunlooprunspecific + 476 43 corefoundation                 0x2472c1c3 cfrunloopruninmode + 106 44 graphicsservices               0x2bd59201 gseventrunmodal + 136 45 uikit                          0x27d9643d uiapplicationmain + 1440 46 appname                        0x000c1d68 main (appdelegate.swift:17) 

removed subclassing concept, created 1 view , added mkmapview sub view. seeing following crash

crash log

thread : crashed: com.apple.main-thread  0  libgpusupportmercury.dylib     0x2fc468fe gpus_returnnotpermittedkillclient  1  libgpusupportmercury.dylib     0x2fc473cb gpussubmitdatabuffers  2  libgpusupportmercury.dylib     0x2fc47249 gldcreatecontext  3  glengine                       0x2b87393b glicreatecontextwithshared  4  opengles                       0x2b94fab3 -[eaglcontext initwithapi:properties:] + 406  5  opengles                       0x2b94f86f -[eaglcontext initwithapi:sharedwithcompute:] + 142  6  vectorkit                      0x33ffde8b ggl::oescontext::oescontext(ggl::gldevice*, std::__1::shared_ptr<ggl::oessharegroup>) + 530  7  vectorkit                      0x33ff6e77 ggl::gldevice::createrenderer() + 110  8  vectorkit                      0x33f1399b -[mddisplaylayer _creategllayer] + 166  9  vectorkit                      0x33f1373b -[mddisplaylayer init] + 70  10 vectorkit                      0x33c3eae3 -[vkmapview initwithglobe:shouldrasterize:inbackground:] + 486  11 mapkit                         0x2a6586d7 -[mkbasicmapview initwithframe:andglobe:shouldrasterize:] + 362 12 mapkit                         0x2a68a67f -[mkmapview _commoninitfromib:gesturerecognizerhostview:showsattribution:] + 1018 13 mapkit                         0x2a676b83 -[mkmapview initwithframe:] + 130 14 uikit                          0x2c44df19 -[uiview init] + 44 15 appname                        0x000f7598 @!objc objectivec.mkmapview.init (objectivec.mkmapview.type)() -> objectivec.mkmapview (customemap.swift) 16 appname                        0x000f4f1c objectivec.mkmapview.__allocating_init (objectivec.mkmapview.type)() -> objectivec.mkmapview (customemap.swift) 17 appname                        0x000ef614 appname.customemap.awakefromnib (appname.customemap)() -> () (customemap.swift:31) 18 appname                        0x000f06ec @objc appname.customemap.awakefromnib (appname.customemap)() -> () (customemap.swift) 19 uikit                          0x2c7ee561 -[uinib instantiatewithowner:options:] + 1680 20 uikit                          0x2c70d303 -[uiviewcontroller _loadviewfromnibnamed:bundle:] + 238 21 uikit                          0x2c54c805 -[uiviewcontroller loadview] + 92 22 uikit                          0x2c430af9 -[uiviewcontroller loadviewifrequired] + 68 23 uikit                          0x2c4dab75 -[uinavigationcontroller _layoutviewcontroller:] + 32 24 uikit                          0x2c4daa9d -[uinavigationcontroller _updatescrollviewfromviewcontroller:toviewcontroller:] + 228 25 uikit                          0x2c4da033 -[uinavigationcontroller _starttransition:fromviewcontroller:toviewcontroller:] + 74 26 uikit                          0x2c4d9d63 -[uinavigationcontroller _startdeferredtransitionifneeded:] + 578 27 uikit                          0x2c4d9acd -[uinavigationcontroller __viewwilllayoutsubviews] + 44 28 uikit                          0x2c4d9a61 -[uilayoutcontainerview layoutsubviews] + 184 29 uikit                          0x2c42e24f -[uiview(calayerdelegate) layoutsublayersoflayer:] + 514 30 quartzcore                     0x2be56a0d -[calayer layoutsublayers] + 136 31 quartzcore                     0x2be523e5 ca::layer::layout_if_needed(ca::transaction*) + 360 32 quartzcore                     0x2be5226d ca::layer::layout_and_display_if_needed(ca::transaction*) + 16 33 quartzcore                     0x2be51c51 ca::context::commit_transaction(ca::transaction*) + 224 34 quartzcore                     0x2be51a55 ca::transaction::commit() + 324 35 uikit                          0x2c4266e5 _aftercacommithandler + 132 36 corefoundation                 0x28f34d95 __cfrunloop_is_calling_out_to_an_observer_callback_function__ + 20 37 corefoundation                 0x28f32453 __cfrunloopdoobservers + 278 38 corefoundation                 0x28f3285b __cfrunlooprun + 914 39 corefoundation                 0x28e803c1 cfrunlooprunspecific + 476 40 corefoundation                 0x28e801d3 cfrunloopruninmode + 106 41 graphicsservices               0x302550a9 gseventrunmodal + 136 42 uikit                          0x2c48ffa1 uiapplicationmain + 1440 43 appname                        0x000eb500 main (appdelegate.swift:21) 44 libdyld.dylib                  0x36fa6aaf start + 2 

somebody please find i'm missing here.

it looks subclass messing original initialization methods. docs mkmapview should not subclass, use delegate need.

although should not subclass mkmapview class itself, can information map view’s behavior providing delegate object.

i suggest create custom uiview subclass, contains mkmapview , acts delegate. first step i'd take try resolve this.


Comments