init(fullAddress:shortAddress:)
Initializes a new address with a location’s full address using a string and a short address that provides an abbreviated form of the address such as a street address.
Declaration
init?(fullAddress: String, shortAddress: String?)Parameters
- fullAddress:
A string that represents a place’s full address.
- shortAddress:
A compact, short form of the address, such as the location’s street address and city.
Discussion
Use this initializer to create a new MKAddress with a complete address and a short abbreviated address, such as a street address and city.
When you intend to use the MKAddress instance with an MKMapItem to display a Place Card, use multi-line strings when specifying the fullAddress. Doing this enables the framework to ensure the best user experience.
You can provide this using Swift’s multi-line strings using triple-quotes, as shown here.
let metMuseum = MKAddress(fullAddress:
"""
The Metropolitan Museum of Art
1000 Fifth Avenue
New York, NY, 10028
"""",
shortAddress: "1000 Fifth Avenue, New York")Another, equivalent, method is providing the same full address information on a single line using embedded newline characters (”\n”) as shown here.
let metMuseum = MKAddress(fullAddress:"The Metropolitan Museum of Art \n 1000 Fifth Avenue \n New York, NY, 10028", shortAddress: "1000 Fifth Avenue")