I want to modify the values of a CNPostalAddress
, which I obtained from the postalAddress
property of a CLPlacemark
.
Since CNPostalAddress
has immutable properties, I want to convert it to a CNMutablePostalAddress
. However, there doesn't seem to be a clean way to do that. My current method is this:
extension CNPostalAddress {
var mutableAddress: CNMutablePostalAddress {
let address = CNMutablePostalAddress()
address.city = city
address.country = country
address.postalCode = postalCode
address.state = state
address.street = street
[...]
return address
}
}
Is there a better way to do this conversion?
CNPostalAddress
is a class that extendsNSObject
. This means you have access tomutableCopy
.No need to copy individual properties.
Or as an update to your extension: