Subclassing MKMapView and adding an internal property called "mapRegion" crashes with a NSInvalidArgumentException

Originator:a.cecilia.luque
Number:rdar://34257975 Date Originated:September 6 2017, 12:51 AM
Status:DUPLICATE OF 34375315, OPEN Resolved:
Product:iOS + SDK, MapKit Product Version:
Classification: Reproducible:Always
 
Summary: 
In a project using Swift 3.2, when subclassing MKMapView and creating a property called "mapRegion", after the initialisation of the MKMapView  subclass a NSInvalidArgumentException crash happens with the description: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[testMap.UMBMapView copyWithZone:]: unrecognized selector sent to instance 0x11c818800

The crash can be avoided by:
- Renaming the property from "mapRegion" to other different name.
- Making the "mapRegion" property private.
- Compiling the project with Swift4.0.

Not reproducible with simulator.

Steps to Reproduce: 
1- Open the attached project with xCode 9 beta 6.
2- Run the project in iOS11 beta 9 (15A5370a) in an iPhone5S.


Expected Results:
The example project runs, and the app starts with the map view covering all the screen.


Actual Results:
The app crashes saying: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[testMap.UMBMapView copyWithZone:]: unrecognized selector sent to instance 0x11c818800'


Version/Build:
Computer: MacOS Sierra 10.12.6.
xCode: Version 9.0 beta 6 (9M214v)
Project using Swift 3.2.
Device: iPhone5S, iOS11.0 (15A5370a).

Comments

Engineering has provided the following information regarding this issue: This is happening because the user accidentally over-rode a private property in the subclass which they are allowed to do. We should rename the private property to use the private/internal property name convention so this crash does not happen. We will fix this in future release, but for now the recommended workaround is one of the things the developer suggested: - Renaming the property from "mapRegion" to other different name.

By a.cecilia.luque at Sept. 20, 2017, 7:45 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!