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; return YES;
} }
- (PostsViewController *)postsViewController - (PostsViewController *)postsViewController {
{
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController; UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = splitViewController.viewControllers.firstObject; UINavigationController *navigationController = splitViewController.viewControllers.firstObject;
PostsViewController *postsViewController = (PostsViewController *)navigationController.viewControllers.firstObject; PostsViewController *postsViewController = (PostsViewController *)navigationController.viewControllers.firstObject;

View file

@ -35,15 +35,13 @@ NSString *BlogPostDeletedNotification = @"BlogPostDeletedNotification";
return self; return self;
} }
- (NSMutableURLRequest *)previewRequestWithPath:(NSString *)path; - (NSMutableURLRequest *)previewRequestWithPath:(NSString *)path {
{
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[_service urlFor:path]]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[_service urlFor:path]];
[request addValue:@"text/html" forHTTPHeaderField:@"Accept"]; [request addValue:@"text/html" forHTTPHeaderField:@"Accept"];
return request; return request;
} }
- (PMKPromise *)requestBlogStatusWithCaching:(BOOL)useCache; - (PMKPromise *)requestBlogStatusWithCaching:(BOOL)useCache {
{
BlogStatus *status = useCache ? [_store blogStatus] : nil; BlogStatus *status = useCache ? [_store blogStatus] : nil;
if (status) { if (status) {
return [PMKPromise promiseWithValue: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; NSArray *posts = useCache ? [_store drafts] : nil;
if (posts) { if (posts) {
return [PMKPromise promiseWithValue: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; NSArray *posts = useCache ? [_store publishedPosts] : nil;
if (posts) { if (posts) {
return [PMKPromise promiseWithValue:posts]; return [PMKPromise promiseWithValue:posts];
@ -84,11 +80,11 @@ NSString *BlogPostDeletedNotification = @"BlogPostDeletedNotification";
} }
} }
- (PMKPromise *)requestAllPostsWithCaching:(BOOL)useCache; - (PMKPromise *)requestAllPostsWithCaching:(BOOL)useCache {
{ return [PMKPromise when:@[[self requestDraftsWithCaching:useCache], [self requestPublishedPostsWithCaching:useCache]]]
return [PMKPromise when:@[[self requestDraftsWithCaching:useCache], [self requestPublishedPostsWithCaching:useCache]]].then(^(NSArray *results) { .then(^(NSArray *results) {
return [results.firstObject arrayByAddingObjectsFromArray:results.lastObject]; return [results.firstObject arrayByAddingObjectsFromArray:results.lastObject];
}); });
} }
- (PMKPromise *)requestPostWithPath:(NSString *)path { - (PMKPromise *)requestPostWithPath:(NSString *)path {

View file

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

View file

@ -13,7 +13,7 @@
#import "BlogStatus.h" #import "BlogStatus.h"
#import "Post.h" #import "Post.h"
NSString * const BlogServiceErrorDomain = @"BlogServiceErrorDomain"; NSString *const BlogServiceErrorDomain = @"BlogServiceErrorDomain";
@interface BlogService () @interface BlogService ()
@ -90,11 +90,12 @@ NSString * const BlogServiceErrorDomain = @"BlogServiceErrorDomain";
} }
- (PMKPromise *)requestCreateDraftWithID:(NSString *)draftID title:(NSString *)title body:(NSString *)body link:(NSString *)link { - (PMKPromise *)requestCreateDraftWithID:(NSString *)draftID title:(NSString *)title body:(NSString *)body link:(NSString *)link {
NSDictionary *fields = @{@"id": draftID, NSDictionary *fields = @{
@"title": title, @"id" : draftID,
@"body": body, @"title" : title,
@"link": link ?: [NSNull null], @"body" : body,
}; @"link" : link ?: [NSNull null],
};
return [self.client postJSON:[self urlFor:@"/posts/drafts"] headers:nil fields:fields].then([self decodePostBlock]); 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 { - (PMKPromise *)requestUpdatePostWithPath:(NSString *)path title:(NSString *)title body:(NSString *)body link:(NSString *)link {
NSDictionary *fields = @{@"title": title, NSDictionary *fields = @{
@"body": body, @"title" : title,
@"link": link ?: [NSNull null], @"body" : body,
}; @"link" : link ?: [NSNull null],
};
return [self.client putJSON:[self urlFor:path] headers:nil fields:fields]; return [self.client putJSON:[self urlFor:path] headers:nil fields:fields];
} }

View file

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

View file

@ -11,16 +11,15 @@
@implementation BlogStatus @implementation BlogStatus
+ (NSDictionary *)JSONKeyPathsByPropertyKey { + (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{@"localVersion": @"local-version", return @{
@"remoteVersion": @"remote-version", @"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]; self = [super initWithDictionary:dictionaryValue error:error];
if (self) if (self) {
{
_date = [NSDate date]; _date = [NSDate date];
} }
return self; return self;

View file

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

View file

@ -55,8 +55,7 @@
[self configureView]; [self configureView];
} }
- (void)viewWillAppear:(BOOL)animated; - (void)viewWillAppear:(BOOL)animated {
{
[super viewWillAppear:animated]; [super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(savePostBody) name:UIApplicationWillResignActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(savePostBody) name:UIApplicationWillResignActiveNotification object:nil];
} }
@ -93,5 +92,4 @@
} }
} }
@end @end

View file

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

View file

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

View file

@ -27,12 +27,10 @@
__block NSDictionary *metadata = nil; __block NSDictionary *metadata = nil;
[_connection readWithBlock:^(YapDatabaseReadTransaction *transaction) { [_connection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
[transaction getObject:&status metadata:&metadata forKey:@"status" inCollection:@"BlogStatus"]; [transaction getObject:&status metadata:&metadata forKey:@"status" inCollection:@"BlogStatus"];
if (status && metadata) if (status && metadata) {
{
NSNumber *timestamp = metadata[@"timestamp"]; NSNumber *timestamp = metadata[@"timestamp"];
NSTimeInterval age = [NSDate date].timeIntervalSince1970 - [timestamp unsignedIntegerValue]; NSTimeInterval age = [NSDate date].timeIntervalSince1970 - [timestamp unsignedIntegerValue];
if (age > 300) if (age > 300) {
{
NSLog(@"Blog status is stale (%@s old)", @(age)); NSLog(@"Blog status is stale (%@s old)", @(age));
status = nil; status = nil;
} }

View file

@ -44,13 +44,13 @@
if (match.location != NSNotFound) { if (match.location != NSNotFound) {
NSString *rest = [self substringFromIndex:match.location + match.length]; NSString *rest = [self substringFromIndex:match.location + match.length];
return [[[self substringToIndex:match.location] return [[[self substringToIndex:match.location]
stringByAppendingString:replacement] stringByAppendingString:replacement]
stringByAppendingString:rest]; stringByAppendingString:rest];
} }
return [self copy]; return [self copy];
} }
- (NSString *) mm_stringByURLEncoding { - (NSString *)mm_stringByURLEncoding {
return (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, return (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,
(CFStringRef)self, (CFStringRef)self,
NULL, NULL,

View file

@ -25,11 +25,12 @@
@synthesize formattedDate = _formattedDate; @synthesize formattedDate = _formattedDate;
+ (NSDictionary *)JSONKeyPathsByPropertyKey { + (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{@"objectID": @"id", return @{
@"path": @"url", @"objectID" : @"id",
@"url": @"link", @"path" : @"url",
@"time": @"", // ignore @"url" : @"link",
}; @"time" : @"", // ignore
};
} }
+ (NSValueTransformer *)urlJSONTransformer { + (NSValueTransformer *)urlJSONTransformer {
@ -120,10 +121,10 @@
- (NSString *)slug { - (NSString *)slug {
if (!_slug && !self.draft && self.title) { if (!_slug && !self.draft && self.title) {
_slug = [[[[[self.title lowercaseString] _slug = [[[[[self.title lowercaseString]
mm_stringByReplacing:@"'" with:@""] mm_stringByReplacing:@"'" with:@""]
mm_stringByReplacing:@"[^[:alpha:]\\d_]" with:@"-"] mm_stringByReplacing:@"[^[:alpha:]\\d_]" with:@"-"]
mm_stringByReplacing:@"^-+|-+$" with:@""] mm_stringByReplacing:@"^-+|-+$" with:@""]
mm_stringByReplacing:@"-+" with:@"-"]; mm_stringByReplacing:@"-+" with:@"-"];
} }
return _slug; return _slug;
} }

View file

@ -21,8 +21,7 @@
self.backgroundColor = [UIColor colorWithWhite:0.1333 alpha:1.0]; 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 *backgroundColor = [UIColor colorWithWhite:0.1333 alpha:1.0];
UIColor *textColor = [UIColor whiteColor]; UIColor *textColor = [UIColor whiteColor];
if (selected) { if (selected) {

View file

@ -41,8 +41,7 @@
[self setupTitleView]; [self setupTitleView];
} }
- (void)setupTitleView; - (void)setupTitleView {
{
UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 44)]; UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 44)];
titleView.userInteractionEnabled = YES; titleView.userInteractionEnabled = YES;
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(requestStatusWithoutCaching)]; UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(requestStatusWithoutCaching)];
@ -64,8 +63,7 @@
[self.view setNeedsLayout]; [self.view setNeedsLayout];
} }
- (void)viewDidLayoutSubviews; - (void)viewDidLayoutSubviews {
{
[super viewDidLayoutSubviews]; [super viewDidLayoutSubviews];
[UIView animateWithDuration:0.3 animations:^{ [UIView animateWithDuration:0.3 animations:^{
CGFloat width = CGRectGetWidth(self.titleLabel.superview.bounds); 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]; 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 invalidate];
self.blogStatusTimer = nil; self.blogStatusTimer = nil;
} }
@ -91,8 +87,7 @@
self.editorViewController = (EditorViewController *)detailNavController.topViewController; self.editorViewController = (EditorViewController *)detailNavController.topViewController;
} }
- (void)updateStatusLabel:(NSString *)blogStatus; - (void)updateStatusLabel:(NSString *)blogStatus {
{
if (self.statusLabel && ![self.statusLabel.text isEqualToString:blogStatus]) { if (self.statusLabel && ![self.statusLabel.text isEqualToString:blogStatus]) {
self.statusLabel.text = blogStatus; self.statusLabel.text = blogStatus;
[UIView animateWithDuration:0.3 animations:^{ [UIView animateWithDuration:0.3 animations:^{
@ -102,9 +97,9 @@
} }
} }
- (void)updateBlogStatus; - (void)updateBlogStatus {
{ [self updateStatusLabel:[NSString stringWithFormat:@"%@ as of %@", self.blogStatusText,
[self updateStatusLabel:[NSString stringWithFormat:@"%@ as of %@", self.blogStatusText, [self.blogStatusDate mm_relativeToNow]]]; [self.blogStatusDate mm_relativeToNow]]];
} }
- (void)viewWillAppear:(BOOL)animated { - (void)viewWillAppear:(BOOL)animated {
@ -116,8 +111,7 @@
} }
} }
- (void)viewWillDisappear:(BOOL)animated; - (void)viewWillDisappear:(BOOL)animated {
{
[super viewWillDisappear:animated]; [super viewWillDisappear:animated];
[self teardownBlogStatusTimer]; [self teardownBlogStatusTimer];
} }
@ -153,8 +147,7 @@
}); });
} }
- (PMKPromise *)requestPostsWithCaching:(BOOL)useCache; - (PMKPromise *)requestPostsWithCaching:(BOOL)useCache {
{
return [self.blogController requestAllPostsWithCaching:useCache].then(^(NSArray *posts) { return [self.blogController requestAllPostsWithCaching:useCache].then(^(NSArray *posts) {
self.posts = [posts mutableCopy]; self.posts = [posts mutableCopy];
[self.tableView reloadData]; [self.tableView reloadData];

View file

@ -6,8 +6,7 @@
@implementation UIColor (Hex) @implementation UIColor (Hex)
+ (UIColor *)mm_colorFromInteger:(NSUInteger)color; + (UIColor *)mm_colorFromInteger:(NSUInteger)color {
{
unsigned char red = color >> 16; unsigned char red = color >> 16;
unsigned char green = (color >> 8) & 0xff; unsigned char green = (color >> 8) & 0xff;
unsigned char blue = color & 0xff; unsigned char blue = color & 0xff;

View file

@ -7,9 +7,10 @@
// //
@import UIKit; @import UIKit;
#import "AppDelegate.h" #import "AppDelegate.h"
int main(int argc, char * argv[]) { int main(int argc, char *argv[]) {
@autoreleasepool { @autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
} }