code style

This commit is contained in:
Sami Samhuri 2015-04-22 00:26:22 -07:00
parent ac9c969cfb
commit c702143073
17 changed files with 62 additions and 76 deletions

View file

@ -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;

View file

@ -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,9 +80,9 @@ NSString *BlogPostDeletedNotification = @"BlogPostDeletedNotification";
}
}
- (PMKPromise *)requestAllPostsWithCaching:(BOOL)useCache;
{
return [PMKPromise when:@[[self requestDraftsWithCaching:useCache], [self requestPublishedPostsWithCaching:useCache]]].then(^(NSArray *results) {
- (PMKPromise *)requestAllPostsWithCaching:(BOOL)useCache {
return [PMKPromise when:@[[self requestDraftsWithCaching:useCache], [self requestPublishedPostsWithCaching:useCache]]]
.then(^(NSArray *results) {
return [results.firstObject arrayByAddingObjectsFromArray:results.lastObject];
});
}

View file

@ -7,6 +7,7 @@
//
@import Foundation;
#import <PromiseKit/PromiseKit.h>
extern NSString *const BlogServiceErrorDomain;

View file

@ -90,7 +90,8 @@ NSString * const BlogServiceErrorDomain = @"BlogServiceErrorDomain";
}
- (PMKPromise *)requestCreateDraftWithID:(NSString *)draftID title:(NSString *)title body:(NSString *)body link:(NSString *)link {
NSDictionary *fields = @{@"id": draftID,
NSDictionary *fields = @{
@"id" : draftID,
@"title" : title,
@"body" : body,
@"link" : link ?: [NSNull null],
@ -107,7 +108,8 @@ NSString * const BlogServiceErrorDomain = @"BlogServiceErrorDomain";
}
- (PMKPromise *)requestUpdatePostWithPath:(NSString *)path title:(NSString *)title body:(NSString *)body link:(NSString *)link {
NSDictionary *fields = @{@"title": title,
NSDictionary *fields = @{
@"title" : title,
@"body" : body,
@"link" : link ?: [NSNull null],
};

View file

@ -7,6 +7,7 @@
//
@import Foundation;
#import <Mantle/Mantle.h>
@interface BlogStatus : MTLModel <MTLJSONSerializing>

View file

@ -11,16 +11,15 @@
@implementation BlogStatus
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{@"localVersion": @"local-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;

View file

@ -17,4 +17,3 @@
@property (strong, nonatomic) Post *post;
@end

View file

@ -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

View file

@ -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;
}

View file

@ -25,7 +25,8 @@
@synthesize formattedDate = _formattedDate;
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{@"objectID": @"id",
return @{
@"objectID" : @"id",
@"path" : @"url",
@"url" : @"link",
@"time" : @"", // ignore

View file

@ -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) {

View file

@ -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];

View file

@ -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;

View file

@ -7,6 +7,7 @@
//
@import UIKit;
#import "AppDelegate.h"
int main(int argc, char *argv[]) {