Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Contact {
- //holds whichever properties you need to create a CNContact
- }
- protocol ContactsHolder {
- func save(contact: Contact)
- func add(contact: Contact)
- func delete(contact: Contact)
- func update(contact: Contact)
- //Maybe more methods, the important thing is that you abstract yourself away from CNContactStore and other Contact kit classes
- }
- enum ContactsUpdateMethod {
- case save(Contact)
- case add(Contact)
- case delete(Contact)
- case update(Contact)
- }
- protocol ContactsHolder {
- func execute(_ method: ContactsUpdateMethod)
- }
- class CNContactsHolder: ContactsHolder {
- func save(contact: Contact) {
- //1. create a `CNContact` from your `Contact`
- //2. create a saveRequest
- //3. execute: CNContactStore().execute(saveRequest)
- }
- ....
- }
- let contactsHolder: ContactsHolder
- init(contactsHolder: ContactsHolder = CNContactsHolder()) {
- self.contactsHolder = contactsHolder
- }
- let contactsHolder: ContactsHolder
- var contactsHolder: ContactsHolder = CNContactsHolder()
- struct MockContactsHolder: ContactsHolder {
- var saveWasCalled = false
- func save(contact: Contact) {
- saveWasCalled = true
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement