diff --git a/Blog/AppDelegate.m b/Blog/AppDelegate.m index 547a154..26d8c04 100644 --- a/Blog/AppDelegate.m +++ b/Blog/AppDelegate.m @@ -30,8 +30,7 @@ return YES; } -- (PostsViewController *)postsViewController -{ +- (PostsViewController *)postsViewController { UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController; UINavigationController *navigationController = splitViewController.viewControllers.firstObject; PostsViewController *postsViewController = (PostsViewController *)navigationController.viewControllers.firstObject; diff --git a/Blog/BlogController.m b/Blog/BlogController.m index 585cd9e..5a84e42 100644 --- a/Blog/BlogController.m +++ b/Blog/BlogController.m @@ -35,15 +35,13 @@ NSString *BlogPostDeletedNotification = @"BlogPostDeletedNotification"; return self; } -- (NSMutableURLRequest *)previewRequestWithPath:(NSString *)path; -{ +- (NSMutableURLRequest *)previewRequestWithPath:(NSString *)path { NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[_service urlFor:path]]; [request addValue:@"text/html" forHTTPHeaderField:@"Accept"]; return request; } -- (PMKPromise *)requestBlogStatusWithCaching:(BOOL)useCache; -{ +- (PMKPromise *)requestBlogStatusWithCaching:(BOOL)useCache { BlogStatus *status = useCache ? [_store blogStatus] : nil; if (status) { return [PMKPromise promiseWithValue:status]; @@ -56,8 +54,7 @@ NSString *BlogPostDeletedNotification = @"BlogPostDeletedNotification"; } } -- (PMKPromise *)requestDraftsWithCaching:(BOOL)useCache; -{ +- (PMKPromise *)requestDraftsWithCaching:(BOOL)useCache { NSArray *posts = useCache ? [_store drafts] : nil; if (posts) { return [PMKPromise promiseWithValue:posts]; @@ -70,8 +67,7 @@ NSString *BlogPostDeletedNotification = @"BlogPostDeletedNotification"; } } -- (PMKPromise *)requestPublishedPostsWithCaching:(BOOL)useCache; -{ +- (PMKPromise *)requestPublishedPostsWithCaching:(BOOL)useCache { NSArray *posts = useCache ? [_store publishedPosts] : nil; if (posts) { return [PMKPromise promiseWithValue:posts]; @@ -84,11 +80,11 @@ NSString *BlogPostDeletedNotification = @"BlogPostDeletedNotification"; } } -- (PMKPromise *)requestAllPostsWithCaching:(BOOL)useCache; -{ - return [PMKPromise when:@[[self requestDraftsWithCaching:useCache], [self requestPublishedPostsWithCaching:useCache]]].then(^(NSArray *results) { - return [results.firstObject arrayByAddingObjectsFromArray:results.lastObject]; - }); +- (PMKPromise *)requestAllPostsWithCaching:(BOOL)useCache { + return [PMKPromise when:@[[self requestDraftsWithCaching:useCache], [self requestPublishedPostsWithCaching:useCache]]] + .then(^(NSArray *results) { + return [results.firstObject arrayByAddingObjectsFromArray:results.lastObject]; + }); } - (PMKPromise *)requestPostWithPath:(NSString *)path { diff --git a/Blog/BlogService.h b/Blog/BlogService.h index 5388060..f812cb9 100644 --- a/Blog/BlogService.h +++ b/Blog/BlogService.h @@ -7,9 +7,10 @@ // @import Foundation; + #import -extern NSString * const BlogServiceErrorDomain; +extern NSString *const BlogServiceErrorDomain; typedef NS_ENUM(NSUInteger, BlogServiceErrorCode) { BlogServiceErrorCodeWTF diff --git a/Blog/BlogService.m b/Blog/BlogService.m index 4ec46b9..dd611ad 100644 --- a/Blog/BlogService.m +++ b/Blog/BlogService.m @@ -13,7 +13,7 @@ #import "BlogStatus.h" #import "Post.h" -NSString * const BlogServiceErrorDomain = @"BlogServiceErrorDomain"; +NSString *const BlogServiceErrorDomain = @"BlogServiceErrorDomain"; @interface BlogService () @@ -90,11 +90,12 @@ NSString * const BlogServiceErrorDomain = @"BlogServiceErrorDomain"; } - (PMKPromise *)requestCreateDraftWithID:(NSString *)draftID title:(NSString *)title body:(NSString *)body link:(NSString *)link { - NSDictionary *fields = @{@"id": draftID, - @"title": title, - @"body": body, - @"link": link ?: [NSNull null], - }; + NSDictionary *fields = @{ + @"id" : draftID, + @"title" : title, + @"body" : body, + @"link" : link ?: [NSNull null], + }; return [self.client postJSON:[self urlFor:@"/posts/drafts"] headers:nil fields:fields].then([self decodePostBlock]); } @@ -107,10 +108,11 @@ NSString * const BlogServiceErrorDomain = @"BlogServiceErrorDomain"; } - (PMKPromise *)requestUpdatePostWithPath:(NSString *)path title:(NSString *)title body:(NSString *)body link:(NSString *)link { - NSDictionary *fields = @{@"title": title, - @"body": body, - @"link": link ?: [NSNull null], - }; + NSDictionary *fields = @{ + @"title" : title, + @"body" : body, + @"link" : link ?: [NSNull null], + }; return [self.client putJSON:[self urlFor:path] headers:nil fields:fields]; } diff --git a/Blog/BlogStatus.h b/Blog/BlogStatus.h index 0da48e3..8382e80 100644 --- a/Blog/BlogStatus.h +++ b/Blog/BlogStatus.h @@ -7,6 +7,7 @@ // @import Foundation; + #import @interface BlogStatus : MTLModel diff --git a/Blog/BlogStatus.m b/Blog/BlogStatus.m index a855236..02b580b 100644 --- a/Blog/BlogStatus.m +++ b/Blog/BlogStatus.m @@ -11,16 +11,15 @@ @implementation BlogStatus + (NSDictionary *)JSONKeyPathsByPropertyKey { - return @{@"localVersion": @"local-version", - @"remoteVersion": @"remote-version", - }; + return @{ + @"localVersion" : @"local-version", + @"remoteVersion" : @"remote-version", + }; } -- (instancetype)initWithDictionary:(NSDictionary *)dictionaryValue error:(NSError **)error; -{ +- (instancetype)initWithDictionary:(NSDictionary *)dictionaryValue error:(NSError **)error { self = [super initWithDictionary:dictionaryValue error:error]; - if (self) - { + if (self) { _date = [NSDate date]; } return self; diff --git a/Blog/EditorViewController.h b/Blog/EditorViewController.h index ce82985..6f0919e 100644 --- a/Blog/EditorViewController.h +++ b/Blog/EditorViewController.h @@ -17,4 +17,3 @@ @property (strong, nonatomic) Post *post; @end - diff --git a/Blog/EditorViewController.m b/Blog/EditorViewController.m index fb96d9f..7e1c301 100644 --- a/Blog/EditorViewController.m +++ b/Blog/EditorViewController.m @@ -55,8 +55,7 @@ [self configureView]; } -- (void)viewWillAppear:(BOOL)animated; -{ +- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(savePostBody) name:UIApplicationWillResignActiveNotification object:nil]; } @@ -93,5 +92,4 @@ } } - @end diff --git a/Blog/JSONHTTPClient.h b/Blog/JSONHTTPClient.h index 3b22fe8..8819fdf 100644 --- a/Blog/JSONHTTPClient.h +++ b/Blog/JSONHTTPClient.h @@ -9,7 +9,7 @@ #import #import -extern NSString * const JSONHTTPClientErrorDomain; +extern NSString *const JSONHTTPClientErrorDomain; typedef enum : NSUInteger { JSONHTTPClientErrorCodeWTF, diff --git a/Blog/JSONHTTPClient.m b/Blog/JSONHTTPClient.m index 89e7618..fdb0efb 100644 --- a/Blog/JSONHTTPClient.m +++ b/Blog/JSONHTTPClient.m @@ -8,7 +8,7 @@ #import "JSONHTTPClient.h" -NSString * const JSONHTTPClientErrorDomain = @"JSONHTTPClientErrorDomain"; +NSString *const JSONHTTPClientErrorDomain = @"JSONHTTPClientErrorDomain"; @interface JSONHTTPClient () diff --git a/Blog/ModelStore.m b/Blog/ModelStore.m index aac588e..a07aec7 100644 --- a/Blog/ModelStore.m +++ b/Blog/ModelStore.m @@ -27,12 +27,10 @@ __block NSDictionary *metadata = nil; [_connection readWithBlock:^(YapDatabaseReadTransaction *transaction) { [transaction getObject:&status metadata:&metadata forKey:@"status" inCollection:@"BlogStatus"]; - if (status && metadata) - { + if (status && metadata) { NSNumber *timestamp = metadata[@"timestamp"]; NSTimeInterval age = [NSDate date].timeIntervalSince1970 - [timestamp unsignedIntegerValue]; - if (age > 300) - { + if (age > 300) { NSLog(@"Blog status is stale (%@s old)", @(age)); status = nil; } diff --git a/Blog/NSString+marshmallows.m b/Blog/NSString+marshmallows.m index 1150e98..6e2b7ef 100644 --- a/Blog/NSString+marshmallows.m +++ b/Blog/NSString+marshmallows.m @@ -44,13 +44,13 @@ if (match.location != NSNotFound) { NSString *rest = [self substringFromIndex:match.location + match.length]; return [[[self substringToIndex:match.location] - stringByAppendingString:replacement] + stringByAppendingString:replacement] stringByAppendingString:rest]; } return [self copy]; } -- (NSString *) mm_stringByURLEncoding { +- (NSString *)mm_stringByURLEncoding { return (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)self, NULL, diff --git a/Blog/Post.m b/Blog/Post.m index 8334d33..7075c80 100644 --- a/Blog/Post.m +++ b/Blog/Post.m @@ -25,11 +25,12 @@ @synthesize formattedDate = _formattedDate; + (NSDictionary *)JSONKeyPathsByPropertyKey { - return @{@"objectID": @"id", - @"path": @"url", - @"url": @"link", - @"time": @"", // ignore - }; + return @{ + @"objectID" : @"id", + @"path" : @"url", + @"url" : @"link", + @"time" : @"", // ignore + }; } + (NSValueTransformer *)urlJSONTransformer { @@ -120,10 +121,10 @@ - (NSString *)slug { if (!_slug && !self.draft && self.title) { _slug = [[[[[self.title lowercaseString] - mm_stringByReplacing:@"'" with:@""] - mm_stringByReplacing:@"[^[:alpha:]\\d_]" with:@"-"] - mm_stringByReplacing:@"^-+|-+$" with:@""] - mm_stringByReplacing:@"-+" with:@"-"]; + mm_stringByReplacing:@"'" with:@""] + mm_stringByReplacing:@"[^[:alpha:]\\d_]" with:@"-"] + mm_stringByReplacing:@"^-+|-+$" with:@""] + mm_stringByReplacing:@"-+" with:@"-"]; } return _slug; } diff --git a/Blog/PostCell.m b/Blog/PostCell.m index 6d40362..30c6400 100644 --- a/Blog/PostCell.m +++ b/Blog/PostCell.m @@ -21,8 +21,7 @@ self.backgroundColor = [UIColor colorWithWhite:0.1333 alpha:1.0]; } -- (void)setSelected:(BOOL)selected animated:(BOOL)animated; -{ +- (void)setSelected:(BOOL)selected animated:(BOOL)animated { UIColor *backgroundColor = [UIColor colorWithWhite:0.1333 alpha:1.0]; UIColor *textColor = [UIColor whiteColor]; if (selected) { diff --git a/Blog/PostsViewController.m b/Blog/PostsViewController.m index c870111..0fe5e0a 100644 --- a/Blog/PostsViewController.m +++ b/Blog/PostsViewController.m @@ -41,8 +41,7 @@ [self setupTitleView]; } -- (void)setupTitleView; -{ +- (void)setupTitleView { UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 44)]; titleView.userInteractionEnabled = YES; UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(requestStatusWithoutCaching)]; @@ -64,8 +63,7 @@ [self.view setNeedsLayout]; } -- (void)viewDidLayoutSubviews; -{ +- (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; [UIView animateWithDuration:0.3 animations:^{ CGFloat width = CGRectGetWidth(self.titleLabel.superview.bounds); @@ -74,13 +72,11 @@ }]; } -- (void)setupBlogStatusTimer -{ self.blogStatusTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(updateBlogStatus) userInfo:nil repeats:YES]; +- (void)setupBlogStatusTimer { } -- (void)teardownBlogStatusTimer -{ +- (void)teardownBlogStatusTimer { [self.blogStatusTimer invalidate]; self.blogStatusTimer = nil; } @@ -91,8 +87,7 @@ self.editorViewController = (EditorViewController *)detailNavController.topViewController; } -- (void)updateStatusLabel:(NSString *)blogStatus; -{ +- (void)updateStatusLabel:(NSString *)blogStatus { if (self.statusLabel && ![self.statusLabel.text isEqualToString:blogStatus]) { self.statusLabel.text = blogStatus; [UIView animateWithDuration:0.3 animations:^{ @@ -102,9 +97,9 @@ } } -- (void)updateBlogStatus; -{ - [self updateStatusLabel:[NSString stringWithFormat:@"%@ as of %@", self.blogStatusText, [self.blogStatusDate mm_relativeToNow]]]; +- (void)updateBlogStatus { + [self updateStatusLabel:[NSString stringWithFormat:@"%@ as of %@", self.blogStatusText, + [self.blogStatusDate mm_relativeToNow]]]; } - (void)viewWillAppear:(BOOL)animated { @@ -116,8 +111,7 @@ } } -- (void)viewWillDisappear:(BOOL)animated; -{ +- (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [self teardownBlogStatusTimer]; } @@ -153,8 +147,7 @@ }); } -- (PMKPromise *)requestPostsWithCaching:(BOOL)useCache; -{ +- (PMKPromise *)requestPostsWithCaching:(BOOL)useCache { return [self.blogController requestAllPostsWithCaching:useCache].then(^(NSArray *posts) { self.posts = [posts mutableCopy]; [self.tableView reloadData]; diff --git a/Blog/UIColor+Hex.m b/Blog/UIColor+Hex.m index 0a5aa57..c29e959 100644 --- a/Blog/UIColor+Hex.m +++ b/Blog/UIColor+Hex.m @@ -6,8 +6,7 @@ @implementation UIColor (Hex) -+ (UIColor *)mm_colorFromInteger:(NSUInteger)color; -{ ++ (UIColor *)mm_colorFromInteger:(NSUInteger)color { unsigned char red = color >> 16; unsigned char green = (color >> 8) & 0xff; unsigned char blue = color & 0xff; diff --git a/Blog/main.m b/Blog/main.m index 05a9050..ea23123 100644 --- a/Blog/main.m +++ b/Blog/main.m @@ -7,9 +7,10 @@ // @import UIKit; + #import "AppDelegate.h" -int main(int argc, char * argv[]) { +int main(int argc, char *argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); }