Skip to content

Improve observer lifecycle and KVO compliance - #7

Merged
couchdeveloper merged 1 commit into
mainfrom
improveObsercerLifeCycle
Dec 10, 2025
Merged

Improve observer lifecycle and KVO compliance#7
couchdeveloper merged 1 commit into
mainfrom
improveObsercerLifeCycle

Conversation

@couchdeveloper

Copy link
Copy Markdown
Owner

Changes

1. KVO-Compliant Prefix Validation

File:AppSetting.swift

  • Added automatic dot replacement in AppSettingValues.prefix setter
  • Ensures prefix remains KVO-compliant (dots are not allowed in KVO key paths)
  • Prevents runtime errors when observing UserDefaults changes

Breaking

  • UserDefaultsStore protocol now requires AnyObject conformance

Additional Detail

The observer lifecycle fix addresses a critical issue where SwiftUI views would continue observing old store instances after switching to mock stores in previews. The KVO compliance ensures prefix strings work correctly with Foundation's observation mechanism.

- Ensure prefix property is KVO compliant by replacing dots with underscores
- Fix observer lifecycle: cancel and recreate subscription when store changes
- Add AnyObject constraint to UserDefaultsStore protocol for identity comparison
- Refactor UserDefaultsStoreMock: make helper methods static
@couchdevelopercouchdeveloper added the breaking A change which result in breaking the API. This will increase the major version number by one. label Dec 10, 2025
@couchdeveloper
couchdeveloper merged commit b32c53a into mainDec 10, 2025
2 checks passed
@couchdeveloper
couchdeveloper deleted the improveObsercerLifeCycle branch December 10, 2025 14:24
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breakingA change which result in breaking the API. This will increase the major version number by one.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@couchdeveloper