Skip to content

Commit

Permalink
Import the staged projects.
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkware committed May 26, 2010
1 parent 85a82b2 commit 0e38978
Show file tree
Hide file tree
Showing 584 changed files with 55,730 additions and 3 deletions.
6 changes: 3 additions & 3 deletions LICENSE
@@ -1,6 +1,6 @@
This source tree contains a mixture of original material and packages of
other people's work. These packages carry their own licenses, and the
conditions in this file do not apply to these packages.
This project contains a mixture of original material and source code
packages of other people's work. These packages carry their own licenses,
and the conditions in this file do not apply to these packages.

Copyright (c) 2010 Mike Clark, The Pragmatic Studio

Expand Down
9 changes: 9 additions & 0 deletions code/2-json/.gitignore
@@ -0,0 +1,9 @@
build
*.pbxuser
*.mode1v3
*.perspective
*.perspectivev3
*~.nib
*~.xib
!default.pbxuser
!default.mode1v3
20 changes: 20 additions & 0 deletions code/2-json/Classes/Goal.h
@@ -0,0 +1,20 @@
@interface Goal : NSObject {
NSString *name;
NSString *amount;
NSString *goalId;
NSDate *createdAt;
NSDate *updatedAt;
}

@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *amount;
@property (nonatomic, copy) NSString *goalId;
@property (nonatomic, retain) NSDate *createdAt;
@property (nonatomic, retain) NSDate *updatedAt;

- (id)initWithDictionary:(NSDictionary *)dictionary;

+ (NSArray *)findAllRemote;

@end

58 changes: 58 additions & 0 deletions code/2-json/Classes/Goal.m
@@ -0,0 +1,58 @@
#import "Goal.h"
#import "SBJSON.h"

@implementation Goal

@synthesize name;
@synthesize amount;
@synthesize goalId;
@synthesize createdAt;
@synthesize updatedAt;

- (void)dealloc {
[name release];
[amount release];
[goalId release];
[createdAt release];
[updatedAt release];
[super dealloc];
}

- (id)initWithDictionary:(NSDictionary *)dictionary {
if (self = [super init]) {
self.name = [dictionary valueForKey:@"name"];
self.amount = [NSString stringWithFormat:@"%@",
[dictionary valueForKey:@"amount"]];
self.goalId = [dictionary valueForKey:@"id"];
self.createdAt = [dictionary valueForKey:@"created_at"];
self.updatedAt = [dictionary valueForKey:@"updated_at"];
}
return self;
}

+ (NSArray *)findAllRemote {
NSURL *url = [NSURL URLWithString:@"http://localhost:3000/goals.json"];

NSError *error = nil;

NSString *jsonString =
[NSString stringWithContentsOfURL:url
encoding:NSUTF8StringEncoding
error:&error];

NSMutableArray *goals = [NSMutableArray array];
if (jsonString) {
SBJSON *json = [[SBJSON alloc] init];
NSArray *results = [json objectWithString:jsonString error:&error];
[json release];

for (NSDictionary *dictionary in results) {
Goal *goal = [[Goal alloc] initWithDictionary:dictionary];
[goals addObject:goal];
[goal release];
}
}
return goals;
}

@end
9 changes: 9 additions & 0 deletions code/2-json/Classes/GoalsViewController.h
@@ -0,0 +1,9 @@
#import <UIKit/UIKit.h>

@interface GoalsViewController : UITableViewController {
NSMutableArray *goals;
}

@property (nonatomic, retain) NSArray *goals;

@end
88 changes: 88 additions & 0 deletions code/2-json/Classes/GoalsViewController.m
@@ -0,0 +1,88 @@
#import "GoalsViewController.h"

#import "Goal.h"

@implementation GoalsViewController

@synthesize goals;

#pragma mark -
#pragma mark Memory management

- (void)dealloc {
[goals release];
[super dealloc];
}

#pragma mark -
#pragma mark View lifecycle

- (IBAction)refresh {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
self.goals = [Goal findAllRemote];
[self.tableView reloadData];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

- (void)viewDidLoad {
[super viewDidLoad];

self.title = @"Goals";
self.navigationItem.leftBarButtonItem = self.editButtonItem;

UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
target:self
action:@selector(refresh)];
self.navigationItem.rightBarButtonItem = refreshButton;
[refreshButton release];

[self refresh];
}

#pragma mark -
#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return [goals count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"GoalCellId";

UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:CellIdentifier] autorelease];
}

Goal *goal = [goals objectAtIndex:indexPath.row];

cell.textLabel.text = goal.name;
cell.detailTextLabel.text = goal.amount;

return cell;
}

- (void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView beginUpdates];
if (editingStyle == UITableViewCellEditingStyleDelete) {
[goals removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
[tableView endUpdates];
}

@end

12 changes: 12 additions & 0 deletions code/2-json/Classes/SaveUpAppDelegate.h
@@ -0,0 +1,12 @@
#import <UIKit/UIKit.h>

@interface SaveUpAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *navigationController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;

@end

33 changes: 33 additions & 0 deletions code/2-json/Classes/SaveUpAppDelegate.m
@@ -0,0 +1,33 @@
#import "SaveUpAppDelegate.h"

#import "GoalsViewController.h"

@implementation SaveUpAppDelegate

@synthesize window;
@synthesize navigationController;

#pragma mark -
#pragma mark Memory management

- (void)dealloc {
[navigationController release];
[window release];
[super dealloc];
}

#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
return YES;
}

- (void)applicationWillTerminate:(UIApplication *)application {
// Save data if appropriate
}

@end

0 comments on commit 0e38978

Please sign in to comment.