aybekckaya / sqlitepersistentobjects

Automatically exported from code.google.com/p/sqlitepersistentobjects
0 stars 1 forks source link

enhancement: SQLitePersistentObject implement NSMutableCopying #26

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When editing a SQLitePersistentObject, it would be helpful to work on a copy of 
the object.  
Changes made to the copy could be committed by saving the copy or discarded if 
the user 
cancels the editing action.  Since SQLitePersistentObject has only one instance 
member, 
implementing NSMutableCopying is easy:

#pragma mark -
#pragma mark NSMutableCopying

- (id)mutableCopyWithZone:(NSZone *)zone {
    SQLitePersistentObject *copy = [[[self class] allocWithZone:zone] init];
    [copy setPk:[self pk]];
    return copy;
}

This doesn't appear to break the internal caching since the copy will replace 
the original in the 
cache when the save message is received.

Original issue reported on code.google.com by paule...@gmail.com on 28 Dec 2008 at 11:53

GoogleCodeExporter commented 8 years ago
I've already included this in my earlier submission (14). Each object now has a
"revert" method and ways to check if any data has been altered.

Original comment by ScottALyons on 17 Jan 2009 at 7:46

GoogleCodeExporter commented 8 years ago
Cool, much better than what I'm doing (making a copy and keeping a "dirty" flag 
in my controller).

Original comment by paule...@gmail.com on 19 Jan 2009 at 5:42

GoogleCodeExporter commented 8 years ago
The reversion methods are now handled a bit differently, but are part of the 
trunk.

Original comment by ScottALyons on 28 Feb 2009 at 6:55