Created
May 17, 2016 09:27
-
-
Save Daij-Djan/1de5a4c690616915e99aad63af1728f2 to your computer and use it in GitHub Desktop.
This file contains 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
//MIT | |
import Foundation | |
import Contacts | |
if(NSProcessInfo.processInfo().arguments.count != 2) { | |
print("Usage: CNPurgeGroup %GROUPNAME%") | |
} | |
else { | |
let groupName = NSProcessInfo.processInfo().arguments[1] | |
let store = CNContactStore() | |
let groups = try! store.groupsMatchingPredicate(nil) | |
for group in groups { | |
if(group.name == groupName) { | |
let groupIdentifer = group.identifier | |
let relevantPredicate = CNContact.predicateForContactsInGroupWithIdentifier(groupIdentifer) | |
let contacts = try! store.unifiedContactsMatchingPredicate(relevantPredicate, keysToFetch: [CNContactGivenNameKey]) | |
let saveRequest = CNSaveRequest() | |
for contact in contacts { | |
saveRequest.deleteContact(contact.mutableCopy() as! CNMutableContact) | |
} | |
try! store.executeSaveRequest(saveRequest) | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
since deleting a contact from a group in the contacts app only removes it from the group, I wrote this short snippet to 'purge' a group