Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
584 changed files
with
55,730 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
build | ||
*.pbxuser | ||
*.mode1v3 | ||
*.perspective | ||
*.perspectivev3 | ||
*~.nib | ||
*~.xib | ||
!default.pbxuser | ||
!default.mode1v3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#import <UIKit/UIKit.h> | ||
|
||
@interface GoalsViewController : UITableViewController { | ||
NSMutableArray *goals; | ||
} | ||
|
||
@property (nonatomic, retain) NSArray *goals; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
Oops, something went wrong.