I am trying to create a CNPostalAddress
with some strings in Objective-C. I have street address, city, state, zip and country values. I have tried the code below but it’s not working. Thanks for your valuable time.
CNPostalAddress *postalAddr = [[CNPostalAddress alloc] init];
postalAddr.street = [NSString stringWithFormat:@"%@ %@",street1,street2];// here, I am getting an error: Street property is read only.
Create a CNMutablePostalAddress instead of a CNPostalAddress:
CNMutablePostalAddress *postalAddr = [[CNMutablePostalAddress alloc] init];
postalAddr.street = [NSString stringWithFormat:@"%@ %@", street1, street2];
CNMutablePostalAddress is a subclass of CNPostalAddress, so you can use it like a CNPostalAddress from this point onward.
The above answer rewritten in Swift:
let postalAddr = CNMutablePostalAddress()
postalAddr.street = String(format: "%@ %@", street1, street2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With