Add tool for updating a contact - #72
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new tool for updating a contact, allowing selective modification of contact properties.
- Introduces a new "contacts_update" tool with a comprehensive input schema.
- Implements updates for various contact fields such as name, phone numbers, email addresses, postal addresses, and birthday.
Comment on lines
+225
to
+228
| throw NSError( | ||
| domain: "ContactsService", code: 1, | ||
| userInfo: [NSLocalizedDescriptionKey: "Valid contact identifier required"] | ||
| ) |
There was a problem hiding this comment.
Consider using a custom Swift Error type instead of NSError for a more idiomatic error handling approach in Swift.
Suggested change
| throw NSError( | |
| domain: "ContactsService", code: 1, | |
| userInfo: [NSLocalizedDescriptionKey: "Valid contact identifier required"] | |
| ) | |
| throw ContactsServiceError.invalidIdentifier |
Comment on lines
+267
to
+282
| mutableContact.phoneNumbers = phoneNumbers.compactMap { entry in | ||
| guard case let .string(value) = entry.value | ||
| else { | ||
| return nil | ||
| } | ||
| let labelValue = | ||
| entry.key == "mobile" | ||
| ? CNLabelPhoneNumberMobile | ||
| : entry.key == "work" | ||
| ? CNLabelWork : entry.key == "home" ? CNLabelHome : entry.key | ||
|
|
||
| return CNLabeledValue( | ||
| label: labelValue, | ||
| value: CNPhoneNumber(stringValue: value) | ||
| ) | ||
| } |
There was a problem hiding this comment.
[nitpick] Consider extracting the mapping logic for updating phone numbers, as well as the similar sections for email addresses and postal addresses, into helper functions to reduce repetition and improve maintainability.
Suggested change
| mutableContact.phoneNumbers = phoneNumbers.compactMap { entry in | |
| guard case let .string(value) = entry.value | |
| else { | |
| return nil | |
| } | |
| let labelValue = | |
| entry.key == "mobile" | |
| ? CNLabelPhoneNumberMobile | |
| : entry.key == "work" | |
| ? CNLabelWork : entry.key == "home" ? CNLabelHome : entry.key | |
| return CNLabeledValue( | |
| label: labelValue, | |
| value: CNPhoneNumber(stringValue: value) | |
| ) | |
| } | |
| mutableContact.phoneNumbers = mapToLabeledValues( | |
| input: phoneNumbers, | |
| labelMapping: [ | |
| "mobile": CNLabelPhoneNumberMobile, | |
| "work": CNLabelWork, | |
| "home": CNLabelHome | |
| ], | |
| valueTransformer: { CNPhoneNumber(stringValue: $0) } | |
| ) |
Owner
Author
There was a problem hiding this comment.
Good call. Maybe another time.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(Sorry to inform you that you're no longer a Pisces in my book, @carlpeaslee 🐟)