Permalink
Browse files

Creating post object.

  • Loading branch information...
1 parent 4b34ec8 commit 2727166b017d9d18899a87f763088f8b3c1c09f8 @jsakuda jsakuda committed Jun 15, 2012
@@ -16,6 +16,7 @@
09359FE91588930300B4EA3E /* pin_map@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 09359FE71588930300B4EA3E /* pin_map@2x.png */; };
09359FEB1588974400B4EA3E /* line@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 09359FEA1588974400B4EA3E /* line@2x.png */; };
09359FED1588977500B4EA3E /* line.png in Resources */ = {isa = PBXBuildFile; fileRef = 09359FEC1588977500B4EA3E /* line.png */; };
+ 09517A83158AF4320016EDF8 /* Post.m in Sources */ = {isa = PBXBuildFile; fileRef = 09517A82158AF4320016EDF8 /* Post.m */; };
09A4459C1567A6CD00634C53 /* NSDate+TKCategory.m in Sources */ = {isa = PBXBuildFile; fileRef = 09A4458E1567A6CD00634C53 /* NSDate+TKCategory.m */; };
09A4459D1567A6CD00634C53 /* TapkuLibrary.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 09A4458F1567A6CD00634C53 /* TapkuLibrary.bundle */; };
09A4459E1567A6CD00634C53 /* TKCalendarMonthTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 09A445911567A6CD00634C53 /* TKCalendarMonthTableViewController.m */; };
@@ -102,6 +103,8 @@
09359FE71588930300B4EA3E /* pin_map@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "pin_map@2x.png"; sourceTree = "<group>"; };
09359FEA1588974400B4EA3E /* line@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "line@2x.png"; sourceTree = "<group>"; };
09359FEC1588977500B4EA3E /* line.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = line.png; sourceTree = "<group>"; };
+ 09517A81158AF4320016EDF8 /* Post.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Post.h; sourceTree = "<group>"; };
+ 09517A82158AF4320016EDF8 /* Post.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Post.m; sourceTree = "<group>"; };
09A4458D1567A6CD00634C53 /* NSDate+TKCategory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDate+TKCategory.h"; sourceTree = "<group>"; };
09A4458E1567A6CD00634C53 /* NSDate+TKCategory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = "NSDate+TKCategory.m"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
09A4458F1567A6CD00634C53 /* TapkuLibrary.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = TapkuLibrary.bundle; sourceTree = "<group>"; };
@@ -228,6 +231,8 @@
091E407715731F8900EE1F9E /* Event.m */,
0907D66F15873DF6009C395E /* Location.h */,
0907D67015873DF6009C395E /* Location.m */,
+ 09517A81158AF4320016EDF8 /* Post.h */,
+ 09517A82158AF4320016EDF8 /* Post.m */,
);
path = Model;
sourceTree = "<group>";
@@ -596,6 +601,7 @@
09B27FF6157D55A00015FF1A /* SVProgressHUD.m in Sources */,
0907D664158721E2009C395E /* AboutViewController.m in Sources */,
0907D67115873DF6009C395E /* Location.m in Sources */,
+ 09517A83158AF4320016EDF8 /* Post.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -42,7 +42,7 @@ - (void)viewDidLoad
// Create the date/time text
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
- [formatter setDateFormat:@"EEEE, MMMM d yyyy h:mm z"];
+ [formatter setDateFormat:@"EEEE, MMMM d yyyy h:mm a z"];
[formatter setTimeZone:[NSTimeZone systemTimeZone]];
[[self eventTimeLabel] setText:[formatter stringFromDate:[event startTime]]];
}
View
@@ -1,5 +1,7 @@
#import "HTTPEngine.h"
#import "Event.h"
+#import "Post.h"
+
@implementation HTTPEngine
-(MKNetworkOperation*) posts:
@@ -10,7 +12,13 @@ -(MKNetworkOperation*) posts:
httpMethod:@"GET"];
[op onCompletion:^(MKNetworkOperation *completedOperation) {
NSDictionary *responseDictionary = [completedOperation responseJSON];
- NSMutableArray *posts = [responseDictionary objectForKey:@"posts"];
+ NSMutableArray *jsonPosts = [responseDictionary objectForKey:@"posts"];
+
+ NSMutableArray *posts = [[NSMutableArray alloc] initWithCapacity:[jsonPosts count]];
+ [jsonPosts enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
+ Post *p = [[Post alloc] initWithDictionary:[jsonPosts objectAtIndex:index]];
+ [posts addObject:p];
+ }];
// if([completedOperation isCachedResponse]) {
// NSLog(@"Data from cache %@", responseDictionary);
@@ -55,12 +63,12 @@ -(MKNetworkOperation*) eventsFrom:(NSDate *)startDate
[events addObject:e];
}];
- if([completedOperation isCachedResponse]) {
+// if([completedOperation isCachedResponse]) {
// NSLog(@"Data from cache %@", responseDictionary);
- }
- else {
+// }
+// else {
// NSLog(@"Data from server %@", responseDictionary);
- }
+// }
completionBlock(events);
}
onError:^(NSError* error) {
View
@@ -0,0 +1,19 @@
+//
+// Post.h
+// HI Capacity
+//
+// Created by Julie Ann Sakuda on 6/14/12.
+// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface Post : NSObject
+
+@property (strong, nonatomic) NSString *title;
+@property (strong, nonatomic) NSDate *date;
+@property (strong, nonatomic) NSString *content;
+
+- (id) initWithDictionary:(NSDictionary *)json;
+
+@end
View
@@ -0,0 +1,37 @@
+//
+// Post.m
+// HI Capacity
+//
+// Created by Julie Ann Sakuda on 6/14/12.
+// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
+//
+
+#import "Post.h"
+
+@implementation Post
+
+@synthesize title;
+@synthesize date;
+@synthesize content;
+
+- (id) init {
+ self = [super init];
+ return self;
+}
+
+- (id) initWithDictionary:(NSDictionary *)json {
+ self = [self init];
+
+ title = [[json valueForKey:@"title"] description];
+
+ NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
+ [dateFormat setDateFormat:@"EEE, d MMM yyyy HH:mm:ss ZZZ"];
+ [dateFormat setTimeZone:[NSTimeZone systemTimeZone]];
+ date = [dateFormat dateFromString:[json objectForKey:@"date"]];
+
+ content = [[json valueForKey:@"content"] description];
+
+ return self;
+}
+
+@end
@@ -7,10 +7,11 @@
//
#import <UIKit/UIKit.h>
+#import "Post.h"
@interface PostContentViewController : UIViewController <UIWebViewDelegate, UIScrollViewDelegate>
-@property (strong, nonatomic) NSDictionary *post;
+@property (strong, nonatomic) Post *post;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (strong, nonatomic) IBOutlet UIWebView *contentLabel;
@@ -39,7 +39,7 @@ - (void)viewDidLoad
self.navigationItem.titleView = imageView;
// Set the post title label
- [titleLabel setText:[post objectForKey:@"title"]];
+ [titleLabel setText:[post title]];
[titleLabel setNumberOfLines:0];
[titleLabel sizeToFit]; // Shrink the frame to fit the text
@@ -49,11 +49,11 @@ - (void)viewDidLoad
// Set the date label
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
- [dateFormat setDateFormat:@"EEE, d MMM yyyy HH:mm:ss ZZZ"];
- [dateFormat setTimeZone:[NSTimeZone systemTimeZone]];
- NSDate *newDate = [dateFormat dateFromString:[post objectForKey:@"date"]];
- [dateFormat setDateFormat:@"EEEE, d MMM yyyy h:mm"];
- [dateLabel setText:[NSString stringWithFormat:@"(%@)", [dateFormat stringFromDate:newDate]]];
+// [dateFormat setDateFormat:@"EEE, d MMM yyyy HH:mm:ss ZZZ"];
+// [dateFormat setTimeZone:[NSTimeZone systemTimeZone]];
+// NSDate *newDate = [dateFormat dateFromString:[post objectForKey:@"date"]];
+ [dateFormat setDateFormat:@"EEEE, MMM d yyyy"];
+ [dateLabel setText:[NSString stringWithFormat:@"%@", [dateFormat stringFromDate:[post date]]]];
// Adjust position of the date label
CGRect frame = dateLabel.frame;
@@ -67,7 +67,7 @@ - (void)viewDidLoad
[contentLabel setBackgroundColor:[UIColor clearColor]];
// Wrap the post content is html tags with CSS font information
- NSString* postContent = [post objectForKey:@"content"];
+ NSString* postContent = [post content];
NSString* htmlContentString = [NSString stringWithFormat:
@"<html>"
"<style type=\"text/css\">"
@@ -10,6 +10,7 @@
#import "HTTPEngine.h"
#import "PostContentViewController.h"
#import "SVProgressHUD.h"
+#import "Post.h"
@interface PostsViewController ()
- (void) showLoading;
@@ -91,8 +92,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
- NSDictionary *post = [posts objectAtIndex:[indexPath row]];
- [[cell textLabel] setText:[post objectForKey:@"title"]];
+ Post *post = [posts objectAtIndex:[indexPath row]];
+ [[cell textLabel] setText:[post title]];
return cell;
}

0 comments on commit 2727166

Please sign in to comment.