mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-24 04:46:01 +08:00
Expanded comments and cleaned up more TODO's. Just a couple of bug fixes left in RestKit and styling work on this app!
This commit is contained in:
@@ -62,7 +62,6 @@
|
||||
_bodyTextEditor.text = _post.body;
|
||||
|
||||
// Ensure we are authenticated
|
||||
NSLog(@"All the users are: %@", [DBUser allObjects]);
|
||||
[self presentLoginViewControllerIfNecessary];
|
||||
}
|
||||
|
||||
@@ -77,8 +76,7 @@
|
||||
if (_newAttachment) {
|
||||
// has new attachment. show it. allow update.
|
||||
[items addObject:[TTTableImageItem itemWithText:@"Tap to Replace Image" imageURL:@"" defaultImage:_newAttachment URL:@"db://updateAttachment"]];
|
||||
} else if (![[_post attachmentPath] isWhitespaceAndNewlines]) {
|
||||
// TODO: Create model method to determine if there is an attachment
|
||||
} else if ([_post hasAttachment]) {
|
||||
// Has existing attachment. allow replace
|
||||
NSString* url = _post.attachmentPath;
|
||||
[items addObject:[TTTableImageItem itemWithText:@"Tap to Replace Image" imageURL:url defaultImage:nil URL:@"db://updateAttachment"]];
|
||||
@@ -153,11 +151,9 @@
|
||||
#pragma mark RKObjectLoaderDelegate methods
|
||||
|
||||
- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects {
|
||||
NSLog(@"Loaded Objects: %@", objects);
|
||||
NSLog(@"Status Code: %d", objectLoader.response.statusCode);
|
||||
// Post notification telling view controllers to reload.
|
||||
// TODO: Generalize this notification
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kObjectCreatedUpdatedOrDestroyedNotificationName object:objects];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:DBContentObjectDidChangeNotification object:[objects lastObject]];
|
||||
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#import "DBResourceListTableViewController.h"
|
||||
#import "DBManagedObjectCache.h"
|
||||
#import "DBUser.h"
|
||||
#import "DBContentObject.h"
|
||||
|
||||
@implementation UINavigationBar (CustomImage)
|
||||
|
||||
@@ -62,7 +63,7 @@
|
||||
// or the object graph is manipulated
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(invalidateModel) name:DBUserDidLoginNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(invalidateModel) name:DBUserDidLogoutNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(invalidateModel) name:kObjectCreatedUpdatedOrDestroyedNotificationName object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(invalidateModel) name:DBContentObjectDidChangeNotification object:nil];
|
||||
}
|
||||
|
||||
- (void)viewDidUnload {
|
||||
|
||||
@@ -92,12 +92,9 @@
|
||||
#pragma mark RKObjectLoaderDelegate methods
|
||||
|
||||
- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects {
|
||||
NSLog(@"Loaded Objects: %@", objects);
|
||||
NSLog(@"Status Code: %d", objectLoader.response.statusCode);
|
||||
// Post notification telling view controllers to reload.
|
||||
// TODO: Generalize this notification
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kObjectCreatedUpdatedOrDestroyedNotificationName object:objects];
|
||||
// dismiss.
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:DBContentObjectDidChangeNotification object:[objects lastObject]];
|
||||
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
#import <RestKit/CoreData/CoreData.h>
|
||||
#import "DBUser.h"
|
||||
|
||||
// Posted when a content object has changed
|
||||
extern NSString* const DBContentObjectDidChangeNotification;
|
||||
|
||||
/**
|
||||
* Abstract superclass for content models in the Discussion Board. Provides
|
||||
* common property & method definitions for the system
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
#import "DBContentObject.h"
|
||||
|
||||
NSString* const DBContentObjectDidChangeNotification = @"DBContentObjectDidChangeNotification";
|
||||
|
||||
@implementation DBContentObject
|
||||
|
||||
@dynamic userID;
|
||||
|
||||
@@ -91,4 +91,9 @@
|
||||
*/
|
||||
@property (nonatomic, retain) UIImage* newAttachment;
|
||||
|
||||
/**
|
||||
* Returns YES when there is already an Image attached to this Post
|
||||
*/
|
||||
- (BOOL)hasAttachment;
|
||||
|
||||
@end
|
||||
|
||||
@@ -99,4 +99,8 @@
|
||||
return params;
|
||||
}
|
||||
|
||||
- (BOOL)hasAttachment {
|
||||
return NO == [[self attachmentPath] isWhitespaceAndNewlines];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
*/
|
||||
extern NSString* const DBRestKitBaseURL;
|
||||
|
||||
// TODO: See if we can eliminate or abstract this further
|
||||
extern NSString* const kObjectCreatedUpdatedOrDestroyedNotificationName;
|
||||
/**
|
||||
* Server Environments for conditional compilation
|
||||
*/
|
||||
|
||||
@@ -16,7 +16,3 @@
|
||||
#elif DB_ENVIRONMENT == DB_ENVIRONMENT_PRODUCTION
|
||||
NSString* const DBRestKitBaseURL = @"http://discussionboard.heroku.com";
|
||||
#endif
|
||||
|
||||
// TODO: Eliminate
|
||||
NSString* const kObjectCreatedUpdatedOrDestroyedNotificationName = @"kObjectCreatedUpdatedOrDestroyedNotificationName";
|
||||
|
||||
|
||||
@@ -40,31 +40,46 @@ static NSString* const kDBAccessTokenHTTPHeaderField = @"X-USER-ACCESS-TOKEN";
|
||||
@synthesize window;
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
// Initialize object manager
|
||||
// Initialize the RestKit Object Manager
|
||||
RKObjectManager* objectManager = [RKObjectManager objectManagerWithBaseURL:DBRestKitBaseURL];
|
||||
|
||||
// Set the default refresh rate to 1. This means we should always hit the web if we can.
|
||||
// If the server is unavailable, we will load from the core data cache.
|
||||
// If the server is unavailable, we will load from the Core Data cache.
|
||||
[RKRequestTTModel setDefaultRefreshRate:1];
|
||||
|
||||
// Do not overwrite properties that are missing in the payload to nil.
|
||||
// TODO: Fix! There is a bug where elements that are in the payload
|
||||
// objectManager.mapper.missingElementMappingPolicy = RKIgnoreMissingElementMappingPolicy;
|
||||
// Set nil for any attributes we expect to appear in the payload, but do not
|
||||
objectManager.mapper.missingElementMappingPolicy = RKSetNilForMissingElementMappingPolicy;
|
||||
|
||||
// Initialize object store
|
||||
// We are using the Core Data support, so we have initialized a managed object store backed
|
||||
// with a SQLite database. We are also utilizing the managed object cache support to provide
|
||||
// offline access to locally cached content.
|
||||
objectManager.objectStore = [[[RKManagedObjectStore alloc] initWithStoreFilename:@"DiscussionBoard.sqlite"] autorelease];
|
||||
objectManager.objectStore.managedObjectCache = [[DBManagedObjectCache new] autorelease];
|
||||
|
||||
// Set Up Mapper
|
||||
// TODO: Comment
|
||||
// Set Up the Object Mapper
|
||||
// The object mapper is responsible for mapping JSON encoded representations of objects
|
||||
// back to local object representations. Here we instruct RestKit how to connect
|
||||
// sub-dictionaries of attributes to local classes.
|
||||
RKObjectMapper* mapper = objectManager.mapper;
|
||||
[mapper registerClass:[DBUser class] forElementNamed:@"user"];
|
||||
[mapper registerClass:[DBTopic class] forElementNamed:@"topic"];
|
||||
[mapper registerClass:[DBPost class] forElementNamed:@"post"];
|
||||
|
||||
// Set Up Router
|
||||
// TODO: Comment me!
|
||||
// The router is responsible for generating the appropriate resource path to
|
||||
// GET/POST/PUT/DELETE an object representation. This prevents your code from
|
||||
// becoming littered with identical resource paths as you manipulate common
|
||||
// objects across your application. Note that a single object representation
|
||||
// can be loaded from any number of resource paths. You can also PUT/POST
|
||||
// an object to arbitrary paths by configuring the object loader yourself. The
|
||||
// router is just for configuring the default 'home address' for an object.
|
||||
//
|
||||
// Since we are communicating with a Ruby on Rails backend server, we are using
|
||||
// the Rails router. The Rails router is aware of the Rails pattern of nesting
|
||||
// attributes under the underscored version of the model name. The Rails router
|
||||
// will also not send any attributes in a DELETE request, preventing problems with
|
||||
// forgery protection.
|
||||
RKRailsRouter* router = [[[RKRailsRouter alloc] init] autorelease];
|
||||
[router setModelName:@"user" forClass:[DBUser class]];
|
||||
[router routeClass:[DBUser class] toResourcePath:@"/signup" forMethod:RKRequestMethodPOST];
|
||||
|
||||
Reference in New Issue
Block a user