@@ -263,18 +263,23 @@ final class KeychainHelper {
263263 continue
264264 }
265265
266- let deleteQuery : [ String : Any ] = [
267- kSecClass as String : kSecClassGenericPassword,
268- kSecAttrService as String : service,
269- kSecAttrAccount as String : account,
270- kSecUseDataProtectionKeychain as String : true ,
271- kSecAttrSynchronizable as String : !synchronizable
272- ]
273- let deleteStatus = SecItemDelete ( deleteQuery as CFDictionary )
274- if deleteStatus != errSecSuccess, deleteStatus != errSecItemNotFound {
275- Self . logger. warning (
276- " Migrated item ' \( account, privacy: . public) ' but failed to delete old entry: \( deleteStatus) "
277- )
266+ // When opting IN (synchronizable=true), delete the old local-only item safely.
267+ // When opting OUT (synchronizable=false), keep the synchronizable item — deleting it
268+ // would propagate via iCloud Keychain and remove it from other Macs still opted in.
269+ if synchronizable {
270+ let deleteQuery : [ String : Any ] = [
271+ kSecClass as String : kSecClassGenericPassword,
272+ kSecAttrService as String : service,
273+ kSecAttrAccount as String : account,
274+ kSecUseDataProtectionKeychain as String : true ,
275+ kSecAttrSynchronizable as String : false
276+ ]
277+ let deleteStatus = SecItemDelete ( deleteQuery as CFDictionary )
278+ if deleteStatus != errSecSuccess, deleteStatus != errSecItemNotFound {
279+ Self . logger. warning (
280+ " Migrated item ' \( account, privacy: . public) ' but failed to delete old entry: \( deleteStatus) "
281+ )
282+ }
278283 }
279284
280285 migratedCount += 1
0 commit comments