Skip to content

Add tool for updating a contact - #72

Merged
mattt merged 1 commit into
mainfrom
mattt/update-contact-tool
May 14, 2025
Merged

Add tool for updating a contact#72
mattt merged 1 commit into
mainfrom
mattt/update-contact-tool

Conversation

@mattt

@mattt mattt commented May 14, 2025

Copy link
Copy Markdown
Owner
Screenshot 2025-05-14 at 15 17 03

(Sorry to inform you that you're no longer a Pisces in my book, @carlpeaslee 🐟)

@mattt
mattt requested a review from Copilot May 14, 2025 22:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"]
)

Copilot AI May 14, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, valid

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)
)
}

Copilot AI May 14, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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) }
)

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Maybe another time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants