mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-05-13 11:58:17 +08:00
Get example working. requires three20 to be in projects directory (at the same level as RestKit.)
This commit is contained in:
@@ -8,4 +8,5 @@
|
||||
|
||||
#import "DBEnvironment.h"
|
||||
|
||||
NSString* const kDBBaseURLString = @"http://discussionboard.heroku.com";
|
||||
NSString* const kDBBaseURLString = @"http://localhost:3000";
|
||||
//NSString* const kDBBaseURLString = @"http://discussionboard.heroku.com";
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// DBPost.h
|
||||
// DiscussionBoard
|
||||
//
|
||||
// Created by Jeremy Ellison on 1/7/11.
|
||||
// Copyright 2011 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <RestKit/CoreData/CoreData.h>
|
||||
|
||||
@interface DBPost : RKManagedObject {
|
||||
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) NSString* attachmentContentType;
|
||||
@property (nonatomic, retain) NSString* attachmentFileName;
|
||||
@property (nonatomic, retain) NSNumber* attachmentFileSize;
|
||||
@property (nonatomic, retain) NSString* attachmentPath;
|
||||
@property (nonatomic, retain) NSDate* attachmentUpdatedAt;
|
||||
@property (nonatomic, retain) NSString* body;
|
||||
@property (nonatomic, retain) NSDate* createdAt;
|
||||
@property (nonatomic, retain) NSNumber* topicID;
|
||||
@property (nonatomic, retain) NSDate* updatedAt;
|
||||
@property (nonatomic, retain) NSNumber* userID;
|
||||
@property (nonatomic, retain) NSNumber* postID;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// DBPost.m
|
||||
// DiscussionBoard
|
||||
//
|
||||
// Created by Jeremy Ellison on 1/7/11.
|
||||
// Copyright 2011 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "DBPost.h"
|
||||
|
||||
|
||||
@implementation DBPost
|
||||
|
||||
@dynamic attachmentContentType;
|
||||
@dynamic attachmentFileName;
|
||||
@dynamic attachmentFileSize;
|
||||
@dynamic attachmentPath;
|
||||
@dynamic attachmentUpdatedAt;
|
||||
@dynamic body;
|
||||
@dynamic createdAt;
|
||||
@dynamic topicID;
|
||||
@dynamic updatedAt;
|
||||
@dynamic userID;
|
||||
@dynamic postID;
|
||||
|
||||
+ (NSDictionary*)elementToPropertyMappings {
|
||||
return [NSDictionary dictionaryWithKeysAndObjects:
|
||||
@"id",@"postID",
|
||||
@"topic_id",@"topicID",
|
||||
@"user_id",@"userID",
|
||||
@"created_at",@"createdAt",
|
||||
@"updated_at",@"updatedAt",
|
||||
@"attachment_content_type", @"attachmentContentType",
|
||||
@"attachment_file_name", @"attachmentFileName",
|
||||
@"attachment_file_size", @"attachmentFileSize",
|
||||
@"attachment_path", @"attachmentPath",
|
||||
@"attachment_updated_at", @"attachment_updated_at",
|
||||
nil];
|
||||
}
|
||||
|
||||
+ (NSString*)primaryKeyProperty {
|
||||
return @"postID";
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// DBTopicsTableViewController.h
|
||||
// DiscussionBoard
|
||||
//
|
||||
// Created by Jeremy Ellison on 1/7/11.
|
||||
// Copyright 2011 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Three20/Three20.h>
|
||||
|
||||
@interface DBTopicsTableViewController : TTTableViewController {
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// DBTopicsTableViewController.m
|
||||
// DiscussionBoard
|
||||
//
|
||||
// Created by Jeremy Ellison on 1/7/11.
|
||||
// Copyright 2011 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "DBTopicsTableViewController.h"
|
||||
#import <RestKit/Three20/Three20.h>
|
||||
#import "DBTopic.h"
|
||||
|
||||
@implementation DBTopicsTableViewController
|
||||
|
||||
- (void)loadView {
|
||||
[super loadView];
|
||||
|
||||
self.model = [[[RKRequestTTModel alloc] initWithResourcePath:@"/topics"] autorelease];
|
||||
}
|
||||
|
||||
- (void)didLoadModel:(BOOL)firstTime {
|
||||
RKRequestTTModel* model = (RKRequestTTModel*)self.model;
|
||||
NSMutableArray* items = [NSMutableArray arrayWithCapacity:[model.objects count]];
|
||||
|
||||
for(DBTopic* topic in model.objects) {
|
||||
NSString* url = [NSString stringWithFormat:@"db://topic/%@", topic.topicID];
|
||||
[items addObject:[TTTableTextItem itemWithText:topic.name URL:url]];
|
||||
}
|
||||
NSLog(@"Items: %@", items);
|
||||
self.dataSource = [TTListDataSource dataSourceWithItems:items];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -8,7 +8,9 @@
|
||||
|
||||
#import "DiscussionBoardAppDelegate.h"
|
||||
#import <RestKit/RestKit.h>
|
||||
|
||||
#import <Three20/Three20.h>
|
||||
#import <Three20/Three20+Additions.h>
|
||||
#import "DBTopicsTableViewController.h"
|
||||
#import "DBTopic.h"
|
||||
|
||||
@implementation DiscussionBoardAppDelegate
|
||||
@@ -20,11 +22,23 @@
|
||||
#pragma mark Application lifecycle
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
// Initialize object manager
|
||||
RKObjectManager* objectManager = [RKObjectManager objectManagerWithBaseURL:kDBBaseURLString];
|
||||
|
||||
// Initialize object store
|
||||
objectManager.objectStore = [[[RKManagedObjectStore alloc] initWithStoreFilename:@"DiscussionBoard.sqlite"] autorelease];
|
||||
|
||||
RKObjectMapper* mapper = objectManager.mapper;
|
||||
|
||||
[mapper registerClass:[DBTopic class] forElementNamed:@"topic"];
|
||||
|
||||
[self.window makeKeyAndVisible];
|
||||
// Initialize Three20
|
||||
TTURLMap* map = [[TTNavigator navigator] URLMap];
|
||||
[map from:@"db://topics" toViewController:[DBTopicsTableViewController class]];
|
||||
|
||||
|
||||
TTOpenURL(@"db://topics");
|
||||
[[TTNavigator navigator].window makeKeyAndVisible];
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user