Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow subscript access to docs/properties

The following now work, in Xcode 4.4+:

server[@"dbname"]
db[@"doc_id"]
doc[@"property"]
rev[@"property"]
  • Loading branch information...
commit a98512f202b11c29bc2ef5ff2275b3a3f1cfa801 1 parent 406ff5d
@snej snej authored
View
3  Couch/CouchDatabase.h
@@ -73,6 +73,9 @@ typedef NSString* (^CouchDocumentPathMap)(NSString* documentID);
at a time with the same documentID. */
- (CouchDocument*) documentWithID: (NSString*)docID;
+/** Same as -documentWithID:. Enables "[]" access in Xcode 4.4+ */
+- (id)objectForKeyedSubscript:(NSString*)key;
+
/** Creates a CouchDocument object with no current ID.
The first time you PUT to that document, it will be created on the server (via a POST). */
- (CouchDocument*) untitledDocument;
View
5 Couch/CouchDatabase.m
@@ -134,6 +134,11 @@ - (CouchDocument*) documentWithID: (NSString*)docID {
return doc;
}
+/** Same as -documentWithID:. Enables "[]" access in Xcode 4.4+ */
+- (id)objectForKeyedSubscript:(NSString*)key {
+ return [self documentWithID: key];
+}
+
- (CouchDesignDocument*) designDocumentWithName: (NSString*)name {
return (CouchDesignDocument*)[self documentWithID: [@"_design/" stringByAppendingString: name]];
View
3  Couch/CouchDocument.h
@@ -77,6 +77,9 @@
/** Shorthand for [self.properties objectForKey: key]. */
- (id) propertyForKey: (NSString*)key;
+/** Same as -propertyForKey:. Enables "[]" access in Xcode 4.4+ */
+- (id)objectForKeyedSubscript:(NSString*)key;
+
/** Updates the document with new properties, creating a new revision (Asynchronous.)
The properties dictionary needs to contain a "_rev" key whose value is the current revision's ID; the dictionary returned by -properties will already have this, so if you modify that dictionary you're OK. The exception is if this is a new document, as there is no current revision, so no "_rev" key is needed.
If the PUT succeeds, the operation's resultObject will be set to the new CouchRevision.
View
5 Couch/CouchDocument.m
@@ -234,6 +234,11 @@ - (id) propertyForKey: (NSString*)key {
return [self.currentRevision propertyForKey: key];
}
+/** Same as -propertyForKey:. Enables "[]" access in Xcode 4.4+ */
+- (id)objectForKeyedSubscript:(NSString*)key {
+ return [self.currentRevision propertyForKey: key];
+}
+
- (RESTOperation*) putProperties: (NSDictionary*)properties {
NSParameterAssert(properties != nil);
View
3  Couch/CouchReplication.h
@@ -43,6 +43,7 @@ typedef enum {
unsigned _completed, _total;
CouchReplicationMode _mode;
NSError* _error;
+ NSArray* _currentRequests;
}
/** The local database being replicated to/from. */
@@ -105,4 +106,6 @@ typedef enum {
@property (nonatomic, readonly) CouchReplicationMode mode;
+@property (nonatomic, readonly) NSArray* currentRequests;
+
@end
View
8 Couch/CouchReplication.m
@@ -30,6 +30,7 @@ @interface CouchReplication ()
@property (nonatomic, readwrite) unsigned completed, total;
@property (nonatomic, readwrite, retain) NSError* error;
@property (nonatomic, readwrite) CouchReplicationMode mode;
+@property (nonatomic, readwrite) NSArray* currentRequests;
- (void) stopped;
@end
@@ -76,7 +77,7 @@ - (NSString*) description {
@synthesize pull=_pull, createTarget=_createTarget, continuous=_continuous,
filter=_filter, filterParams=_filterParams, options=_options, headers=_headers,
- OAuth=_oauth, localDatabase=_database;
+ OAuth=_oauth, localDatabase=_database, currentRequests=_currentRequests;
- (RESTOperation*) operationToStart: (BOOL)start {
@@ -248,6 +249,7 @@ - (void) observeValueForKeyPath: (NSString*)keyPath ofObject: (id)object
BOOL active = NO;
NSString* status = nil;
NSArray* error = nil;
+ NSArray* requests = nil;
for (NSDictionary* task in _database.server.activeTasks) {
if ([[task objectForKey:@"type"] isEqualToString:@"Replication"]) {
// Can't look up the task ID directly because it's part of a longer string like
@@ -256,6 +258,7 @@ - (void) observeValueForKeyPath: (NSString*)keyPath ofObject: (id)object
active = YES;
status = $castIf(NSString, [task objectForKey: @"status"]);
error = $castIf(NSArray, [task objectForKey: @"error"]);
+ requests = $castIf(NSArray, [task objectForKey: @"requests"]);
break;
}
}
@@ -276,6 +279,9 @@ - (void) observeValueForKeyPath: (NSString*)keyPath ofObject: (id)object
message = $castIf(NSString, [error objectAtIndex: 1]);
self.error = [RESTOperation errorWithHTTPStatus: status message: message URL: _remote];
}
+
+ if (!$equal(requests, _currentRequests))
+ self.currentRequests = requests;
if (!$equal(status, _status)) {
self.status = status;
View
3  Couch/CouchRevision.h
@@ -55,6 +55,9 @@
/** Shorthand for [self.properties objectForKey: key]. (Synchronous) */
- (id) propertyForKey: (NSString*)key;
+/** Same as -propertyForKey:. Enables "[]" access in Xcode 4.4+ */
+- (id)objectForKeyedSubscript:(NSString*)key;
+
/** Has this object fetched its contents from the server yet? */
@property (readonly) BOOL propertiesAreLoaded;
View
5 Couch/CouchRevision.m
@@ -163,6 +163,11 @@ - (id) propertyForKey: (NSString*)key {
return [self.properties objectForKey: key];
}
+/** Same as -propertyForKey:. Enables "[]" access in Xcode 4.4+ */
+- (id)objectForKeyedSubscript:(NSString*)key {
+ return [self.properties objectForKey: key];
+}
+
- (RESTOperation*) putProperties: (NSDictionary*)properties {
NSParameterAssert(properties != nil);
View
3  Couch/CouchServer.h
@@ -57,6 +57,9 @@
Multiple calls with the same name will return the same CouchDatabase instance. */
- (CouchDatabase*) databaseNamed: (NSString*)name;
+/** Same as -databaseNamed:. Enables "[]" access in Xcode 4.4+ */
+- (id)objectForKeyedSubscript:(NSString*)key;
+
#pragma mark - ACTIVITY:
/** The list of active server tasks, as parsed JSON (observable).
View
6 Couch/CouchServer.m
@@ -139,6 +139,12 @@ - (CouchDatabase*) databaseNamed: (NSString*)name {
return db;
}
+/** Same as -databaseNamed:. Enables "[]" access in Xcode 4.4+ */
+- (id)objectForKeyedSubscript:(NSString*)key {
+ return [self databaseNamed: key];
+}
+
+
#pragma mark - REPLICATOR DATABASE:

0 comments on commit a98512f

Please sign in to comment.
Something went wrong with that request. Please try again.