mirror of
https://github.com/samsonjs/samhuri.net-ios.git
synced 2026-03-25 09:25:47 +00:00
use constants for keys
This commit is contained in:
parent
41f939ef97
commit
33979d0369
4 changed files with 41 additions and 20 deletions
|
|
@ -212,15 +212,23 @@
|
|||
|
||||
#pragma mark - State restoration
|
||||
|
||||
static NSString *const StateRestorationPostKey = @"post";
|
||||
static NSString *const StateRestorationModifiedPostKey = @"modifiedPost";
|
||||
static NSString *const StateRestorationTextViewContentOffsetKey = @"textView.contentOffset";
|
||||
|
||||
- (void)encodeRestorableStateWithCoder:(NSCoder *)coder {
|
||||
[coder encodeObject:self.post forKey:@"post"];
|
||||
[coder encodeObject:self.modifiedPost forKey:@"modifiedPost"];
|
||||
NSLog(@"%@ encode restorable state with coder %@", self, coder);
|
||||
[coder encodeObject:self.post forKey:StateRestorationPostKey];
|
||||
[coder encodeObject:self.modifiedPost forKey:StateRestorationModifiedPostKey];
|
||||
[coder encodeCGPoint:self.textView.contentOffset forKey:StateRestorationTextViewContentOffsetKey];
|
||||
[super encodeRestorableStateWithCoder:coder];
|
||||
}
|
||||
|
||||
- (void)decodeRestorableStateWithCoder:(NSCoder *)coder {
|
||||
self.post = [coder decodeObjectForKey:@"post"];
|
||||
self.modifiedPost = [coder decodeObjectForKey:@"modifiedPost"];
|
||||
NSLog(@"%@ decode restorable state with coder %@", self, coder);
|
||||
self.post = [coder decodeObjectForKey:StateRestorationPostKey];
|
||||
self.modifiedPost = [coder decodeObjectForKey:StateRestorationModifiedPostKey];
|
||||
self.textView.contentOffset = [coder decodeCGPointForKey:StateRestorationTextViewContentOffsetKey];
|
||||
[super decodeRestorableStateWithCoder:coder];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,18 +19,21 @@
|
|||
return self;
|
||||
}
|
||||
|
||||
static NSString *const PostsKey = @"posts";
|
||||
static NSString *const TitleKey = @"title";
|
||||
|
||||
- (id)initWithCoder:(NSCoder *)coder {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_title = [coder decodeObjectForKey:@"title"];
|
||||
_posts = [coder decodeObjectForKey:@"posts"];
|
||||
_title = [coder decodeObjectForKey:TitleKey];
|
||||
_posts = [coder decodeObjectForKey:PostsKey];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)coder {
|
||||
[coder encodeObject:self.title forKey:@"title"];
|
||||
[coder encodeObject:self.posts forKey:@"posts"];
|
||||
[coder encodeObject:self.title forKey:TitleKey];
|
||||
[coder encodeObject:self.posts forKey:PostsKey];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -246,21 +246,26 @@ static const NSUInteger SectionPublished = 1;
|
|||
|
||||
#pragma mark - State restoration
|
||||
|
||||
static NSString *const StateRestorationPostCollectionsKey = @"postCollections";
|
||||
static NSString *const StateRestorationBlogStatusDateKey = @"blogStatusDate";
|
||||
static NSString *const StateRestorationBlogStatusTextKey = @"blogStatusText";
|
||||
static NSString *const StateRestorationTabelViewContentOffsetKey = @"tableView.contentOffset";
|
||||
|
||||
- (void)encodeRestorableStateWithCoder:(NSCoder *)coder {
|
||||
NSLog(@"%@ encode restorable state with coder %@", self, coder);
|
||||
[coder encodeObject:self.postCollections forKey:@"postCollections"];
|
||||
[coder encodeObject:self.blogStatusDate forKey:@"blogStatusDate"];
|
||||
[coder encodeObject:self.blogStatusText forKey:@"blogStatusText"];
|
||||
[coder encodeCGPoint:self.tableView.contentOffset forKey:@"tableView.contentOffset"];
|
||||
[coder encodeObject:self.postCollections forKey:StateRestorationPostCollectionsKey];
|
||||
[coder encodeObject:self.blogStatusDate forKey:StateRestorationBlogStatusDateKey];
|
||||
[coder encodeObject:self.blogStatusText forKey:StateRestorationBlogStatusTextKey];
|
||||
[coder encodeCGPoint:self.tableView.contentOffset forKey:StateRestorationTabelViewContentOffsetKey];
|
||||
[super encodeRestorableStateWithCoder:coder];
|
||||
}
|
||||
|
||||
- (void)decodeRestorableStateWithCoder:(NSCoder *)coder {
|
||||
NSLog(@"%@ decode restorable state with coder %@", self, coder);
|
||||
self.postCollections = [coder decodeObjectForKey:@"postCollections"];
|
||||
self.blogStatusDate = [coder decodeObjectForKey:@"blogStatusDate"];
|
||||
self.blogStatusText = [coder decodeObjectForKey:@"blogStatusText"];
|
||||
self.tableView.contentOffset = [coder decodeCGPointForKey:@"tableView.contentOffset"];
|
||||
self.postCollections = [coder decodeObjectForKey:StateRestorationPostCollectionsKey];
|
||||
self.blogStatusDate = [coder decodeObjectForKey:StateRestorationBlogStatusDateKey];
|
||||
self.blogStatusText = [coder decodeObjectForKey:StateRestorationBlogStatusTextKey];
|
||||
self.tableView.contentOffset = [coder decodeCGPointForKey:StateRestorationTabelViewContentOffsetKey];
|
||||
[super decodeRestorableStateWithCoder:coder];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,19 +41,24 @@
|
|||
[self.webView loadHTMLString:@"<!doctype html><html><head><title></title></head><body></body></html>" baseURL:nil];
|
||||
}
|
||||
|
||||
#pragma mark - State restoration
|
||||
|
||||
static NSString *const StateRestorationInitialRequestKey = @"initialRequest";
|
||||
static NSString *const StateRestorationWebViewRequestURLKey = @"webView.request.URL";
|
||||
|
||||
- (void)encodeRestorableStateWithCoder:(NSCoder *)coder {
|
||||
[coder encodeObject:self.initialRequest forKey:@"initialRequest"];
|
||||
[coder encodeObject:self.webView.request.URL forKey:@"webView.request.URL"];
|
||||
[coder encodeObject:self.initialRequest forKey:StateRestorationInitialRequestKey];
|
||||
[coder encodeObject:self.webView.request.URL forKey:StateRestorationWebViewRequestURLKey];
|
||||
[super encodeRestorableStateWithCoder:coder];
|
||||
}
|
||||
|
||||
- (void)decodeRestorableStateWithCoder:(NSCoder *)coder {
|
||||
NSURL *url = [coder decodeObjectForKey:@"webView.request.URL"];
|
||||
NSURL *url = [coder decodeObjectForKey:StateRestorationWebViewRequestURLKey];
|
||||
if (url) {
|
||||
[self.webView loadRequest:[NSURLRequest requestWithURL:url]];
|
||||
}
|
||||
else {
|
||||
self.initialRequest = [coder decodeObjectForKey:@"initialRequest"];
|
||||
self.initialRequest = [coder decodeObjectForKey:StateRestorationInitialRequestKey];
|
||||
}
|
||||
[super decodeRestorableStateWithCoder:coder];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue