Skip to content

Instantly share code, notes, and snippets.

@LeiHao0
Created July 15, 2015 08:31
Show Gist options
  • Select an option

  • Save LeiHao0/b5e717a4cc0e01b6d11a to your computer and use it in GitHub Desktop.

Select an option

Save LeiHao0/b5e717a4cc0e01b6d11a to your computer and use it in GitHub Desktop.
exchange people's First and Last Name in Mac OSX Contacts
import AddressBook
let addressBook = ABAddressBook.sharedAddressBook()
let firstKey = "First"
let lastKey = "Last"
for people in addressBook.people() {
if let p = people as? ABPerson {
let f: AnyObject? = p.valueForKey(firstKey)
let l: AnyObject? = p.valueForKey(lastKey)
p.setValue(l, forKey: firstKey)
p.setValue(f, forKey: lastKey)
}
}
addressBook.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment