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,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 {

View file

@ -7,9 +7,10 @@
//
@import Foundation;
#import <PromiseKit/PromiseKit.h>
extern NSString * const BlogServiceErrorDomain;
extern NSString *const BlogServiceErrorDomain;
typedef NS_ENUM(NSUInteger, BlogServiceErrorCode) {
BlogServiceErrorCodeWTF

View file

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

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

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

@ -9,7 +9,7 @@
#import <Foundation/Foundation.h>
#import <PromiseKit/PromiseKit.h>
extern NSString * const JSONHTTPClientErrorDomain;
extern NSString *const JSONHTTPClientErrorDomain;
typedef enum : NSUInteger {
JSONHTTPClientErrorCodeWTF,

View file

@ -8,7 +8,7 @@
#import "JSONHTTPClient.h"
NSString * const JSONHTTPClientErrorDomain = @"JSONHTTPClientErrorDomain";
NSString *const JSONHTTPClientErrorDomain = @"JSONHTTPClientErrorDomain";
@interface JSONHTTPClient ()

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

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

View file

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

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,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]));
}