The Keychain Services API allows adding/updating/deleting items from the keychain. However, it doesn't seem to include any mechanism for watching a specific keychain item for changes.
My app is storing a value in the keychain, and I want to be notified if that value gets changed by the user or another process. Is such a thing possible, or will I just have to periodically poll the keychain item and check for changes myself?
Here is API of Security framework for your purpose
/**
@function SecKeychainAddCallback
@abstract Registers your keychain event callback function
@param callbackFunction A pointer to your keychain event callback function, described in SecKeychainCallback. You indicate the type of keychain events you want to receive by passing a bit mask of the desired events in the eventMask parameter.
@param eventMask A bit mask indicating the keychain events that your application wishes to be notified of. See SecKeychainEventMask for a description of this bit mask. The Keychain Manager tests this mask to determine the keychain events that you wish to receive, and passes these events in the keychainEvent parameter of your callback function. See SecKeychainEvent for a description of these events.
@param userContext A pointer to application-defined storage that will be passed to your callback function. Your application can use this to associate any particular call of SecKeychainAddCallback with any particular call of your keychain event callback function.
@result A result code. See "Security Error Codes" (SecBase.h).
*/
public func SecKeychainAddCallback(_ callbackFunction: SecKeychainCallback,
_ eventMask: SecKeychainEventMask,
_ userContext: UnsafeMutableRawPointer?) -> OSStatus