MyLocation App Ch 29 Maps: Crash on actual iPhone XS

A fun real world problem I am trying to debug.

iPhone XS crashes when the Map on the MyLocations App is accesed.

This may be an Apple MapKit problem with a specific device. There is no issue when run on an iPhone 6S for example or run on the simulator.

Steps to reproduce the problem:

  1. Download the “iOS Apprentice iOS_Apprentice_v7.0.zip” from raywenderlich.com Download

  2. Unzip download file

  3. In Xcode open “iOS_Apprentice_v7.0/my-locations/Source Code/29-Maps/chapter-29-final/MyLocations.xcodeproj”

  4. Build and run on a iPhone XS (not on the simulator as there is no issue when run on the simulator)

  5. Tag to add a location to the app

  6. At the bottom right of the screen tap “Map”

  7. App terminates

Xcode indicates the line the app terminates on is “mapView.addAnnotations(locations)” in MapViewController.swift

The crash log on the iphone indicates the app crashed deep in the Apple framework

Thread 0 Crashed:

0 libswiftCore.dylib 0x0000000100aee4bc 0x1007fc000 + 3089596

Crash logs attached.
Tom

2 libobArchive.zip (1.1 MB)
jc.A.dylib 0x00000001f972dc64 objc_allocateClassPair + 156

Tom

Hi Tom, sorry about the issue. Others have reported it too but since it only happens on devices and that too on the very latest ones (at least as far as I can tell), I am unable to reproduce at my end at this point since I do not have an iPhone XR. And without being able to reproduce the issue, I’m unable to find a workaround. But will look into this as soon as I can. Thank you for reporting.

Fahim - No problem. The RW tutorials are fantastic and this was an opportunity to learn more about debugging.

I was able to work a bit more on the issue of the iPhone XS crash when calling mapView(add annotations) where the annotations called are using NSManagedObjects.

I wrote a simplified app to remove the complexity inherent in the MyLocation tutorial and it crashes at the same point with the same information in the crash report. So this is not an issue with the code in the tutorial.

The iPhone XS, XR and XR Max all use the new Apple A12 chip. I am using Xcode 10.1 which has added new support for the arm64e architecture. A few programmers are also mentioning they same type of problem with different applications. What is common is Xcode 10.1, a NSManagedObject and a physical device using the A12 chip (XS, XR and XR Max).

Open radar has a report that someone submitted a Radar on this to Apple and it was closed as a duplicate.

My plan will be to wait for the next production release of Xcode to see if the issue still exists.

Thanks RayWenderlich.com for the excellent tutorial on using Apples crash reports, I needed that to even get started.

Thanks for the excellent sleuthing, Tom :slight_smile: I still don’t have a device with an A12 chip but this was in my list of items to test out when I did eventually get one. Xcode 10.2 should be out within the next month. If you do have the time, please check again when Xcode 10.2 comes out and let me know if the issue still persists.

If the issue is still there, and it continues to be there in the Xcode 11 betas, I’ll be sure to add a note to the next revision of the book indicating the issue since that would certainly help others who might hit the same crash.

Thank you again :slight_smile:

Although I don’t have an A12 iPhone either, I was curious about this error. It doesn’t seem like something that an Xcode version would fix, but rather something for a new version of iOS.

I found a blog article (and later a StackOverflow topic), that pointed out that the documentation specifies that MKAnnotation.coordinate must be KVO compliant. In both cases, addressing this for a class based on NSManagedObject behaved better.

The KVO issue is that our implementation of coordinate is using a computed property, which does not give KVO anything to latch onto. The fix that was helpful was to add an optional func that informs KVO that coordinate is based on latitude and longitude:

  class func keyPathsForValuesAffectingCoordinate() -> Set<String> {
    return Set<String>([ #keyPath(Location.latitude), #keyPath(Location.longitude) ])
  }

Note that the issue the above two posts were addressing was not the crash on XS phones, but rather incomplete behavior in various other scenarios. So it might not help at all. But it does strike me as the kind of “easily overlooked detail” that might be the cause of the crash.

For an app like MyLocations, where the coordinates of a location are never changed once they are set, another way that might address the same KVO issue is to make coordinate a lazy var, rather than a computed property:

  lazy var coordinate: CLLocationCoordinate2D = {
    return CLLocationCoordinate2DMake(latitude, longitude)
  }()

This is a property which gets initialized the first time coordinate is retrieved, but then persists as an actual stored variable, giving KVO something to latch onto.

adamsmorgantom, if you have the time or inclination, maybe you could try either or both of these, and see if they make any difference on an iPhone XS?

I have an XS Max and I get the same crash on the same line of code with these changes. It doesn’t crash on the removeAnnotations line but just the addAnnotations.

Rats.

It is not a pretty bug to have floating around in there. It is reacting as if your Location object is not an Annotation, despite it having the correct implementation of the MKAnnotation protocol. That’s not a good thing!

Great suggestion. I am on travel for 10 days without access to my code but when I get back I will try this out and post back here.

I tried the last suggestion, make coordinate a lazy var and it did not fix the issue. Still get the crash. Haven’t tried the first suggestion because I don’t completely understand it. Once I look into it a little more I will give it a try.

Looks like this crash issue has been fixed with the release of Xcode 10.1. I updated to Xcode Version 10.2 (10E125) and tested on a iPhone XS running iOS 12.1.4. The iOS Apprentice source code was from MyLocation 29-Maps chapter-29-final 2.

Thanks everyone for the great suggestions on this thread.

1 Like

typo on first line should be “release of Xcode 10.2”

Sweet! I would love to know what they did to fix it, and how it happened in the first place.

This topic was automatically closed after 166 days. New replies are no longer allowed.