Created
December 29, 2015 08:49
-
-
Save mortenjust/2109666f0a16463c3127 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Contacts | |
// Convert to the newer CNPostalAddress | |
func postalAddressFromAddressDictionary(addressdictionary: Dictionary<NSObject,AnyObject>) -> CNMutablePostalAddress { | |
let address = CNMutablePostalAddress() | |
address.street = addressdictionary["Street"] as? String ?? "" | |
address.state = addressdictionary["State"] as? String ?? "" | |
address.city = addressdictionary["City"] as? String ?? "" | |
address.country = addressdictionary["Country"] as? String ?? "" | |
address.postalCode = addressdictionary["ZIP"] as? String ?? "" | |
return address | |
} | |
// Create a localized address string from an Address Dictionary | |
func localizedStringForAddressDictionary(addressDictionary: Dictionary<NSObject,AnyObject>) -> String { | |
return CNPostalAddressFormatter.stringFromPostalAddress(postalAddressFromAddressDictionary(addressDictionary), style: .MailingAddress) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment