1.2.0
What's New in 1.2.0
Custom Transaction Merger Support
This release introduces support for custom transaction merger implementations, providing flexibility to handle specific use cases such as undo manager conflicts.
Key Features:
- Public
TransactionMergerProtocol: The protocol is now public, allowing developers to create custom merger implementations - Dependency Injection: Pass custom merger instances via optional
mergerparameter in initializers - Crash Prevention: Solves critical crashes when
NSManagedObjectContextinstances have theirundoManagerproperty configured - Full Backward Compatibility: Existing code continues to work without any changes - defaults to the standard
Merger()implementation
Example Usage:
class CustomTransactionMerger: TransactionMergerProtocol {
func callAsFunction(merge transactions: [NSPersistentHistoryTransaction],
into contexts: [NSManagedObjectContext]) {
for transaction in transactions {
let notification = transaction.objectIDNotification()
for context in contexts {
context.perform {
// Temporarily disable undo manager to prevent crashes
let undoManager = context.undoManager
context.undoManager = nil
context.mergeChanges(fromContextDidSave: notification)
context.undoManager = undoManager
}
}
}
}
}
// Use custom merger
let kit = PersistentHistoryTrackingKit(
// ... other parameters
merger: CustomTransactionMerger()
)Credits
Special thanks to @yangyubo for this excellent contribution! This enhancement provides the flexibility needed to handle complex undo manager scenarios while maintaining the simplicity of the default behavior.
Technical Details
- Follows SOLID principles (Open/Closed Principle)
- Improves testability through dependency injection
- All changes are additive with no breaking changes to the public API
Full Changelog: 1.1.0...1.2.0