Created
February 29, 2012 03:39
-
-
Save pulkitsinghal/1937402 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
... | |
#import "CouchCocoa.h" | |
... | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
... | |
/* Try to connect to the IrisCouch instance */ | |
// 1) Create a server object via the URL | |
NSURL* serverURL = [NSURL URLWithString: @"https://mydomain.iriscouch.com"]; | |
CouchServer *server = [[CouchServer alloc] initWithURL: serverURL]; | |
// 2) Set the credentials | |
[server setCredential:[NSURLCredential credentialWithUser:@"username" | |
password:@"password" | |
persistence:NSURLCredentialPersistenceNone]]; | |
// 3) Express your interest in creating a new database | |
CouchDatabase *database = [server databaseNamed: @"mynewdatabase"]; | |
RESTOperation* op = [database create]; // 3.1) prepare the REST operation | |
if (![op wait]) { // 3.2) make it happen | |
NSLog(@"%@", [op.error localizedDescription]); // 3.3) log any problems | |
} | |
// 4) Express your interest in creating a new document in mynewdatabase | |
CouchDocument *doc = [database untitledDocument]; | |
NSDictionary *keyValuePairs = [NSDictionary dictionaryWithObjectsAndKeys: | |
@"its alive", @"status", nil]; | |
op = [doc putProperties:keyValuePairs]; | |
if (![op wait]) { // 4.2) make it happen | |
NSLog(@"%@", [op.error localizedDescription]); // 4.3) log any problems | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment