You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/03/15 21:45:35 UTC

ios commit: Add an associatedObject field to CDVPluginResult.

Updated Branches:
  refs/heads/master 52702d87c -> b6e3bb46f


Add an associatedObject field to CDVPluginResult.

Could have used objc_setAssociatedObject, but this seems simpler since
we own the class.


Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/b6e3bb46
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/b6e3bb46
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/b6e3bb46

Branch: refs/heads/master
Commit: b6e3bb46f0c342304adeb6702c2903e2c27afe7f
Parents: 52702d8
Author: Andrew Grieve <ag...@chromium.org>
Authored: Mon Mar 11 22:04:29 2013 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Mar 15 16:44:07 2013 -0400

----------------------------------------------------------------------
 CordovaLib/Classes/CDVPluginResult.h |    3 +++
 CordovaLib/Classes/CDVPluginResult.m |   20 ++++++++++----------
 2 files changed, 13 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/b6e3bb46/CordovaLib/Classes/CDVPluginResult.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVPluginResult.h b/CordovaLib/Classes/CDVPluginResult.h
index 8393df2..11b5377 100644
--- a/CordovaLib/Classes/CDVPluginResult.h
+++ b/CordovaLib/Classes/CDVPluginResult.h
@@ -37,6 +37,9 @@ typedef enum {
 @property (nonatomic, strong, readonly) NSNumber* status;
 @property (nonatomic, strong, readonly) id message;
 @property (nonatomic, strong)           NSNumber* keepCallback;
+// This property can be used to scope the lifetime of another object. For example,
+// Use it to store the associated NSData when `message` is created using initWithBytesNoCopy.
+@property (nonatomic, strong) id associatedObject;
 
 - (CDVPluginResult*)init;
 + (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal;

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/b6e3bb46/CordovaLib/Classes/CDVPluginResult.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVPluginResult.m b/CordovaLib/Classes/CDVPluginResult.m
index a03e005..ffc96a2 100644
--- a/CordovaLib/Classes/CDVPluginResult.m
+++ b/CordovaLib/Classes/CDVPluginResult.m
@@ -29,16 +29,16 @@
 @end
 
 @implementation CDVPluginResult
-@synthesize status, message, keepCallback;
+@synthesize status, message, keepCallback, associatedObject;
 
 static NSArray* org_apache_cordova_CommandStatusMsgs;
 
 id messageFromArrayBuffer(NSData* data)
 {
-    return @{
-        @"CDVType" : @"ArrayBuffer",
-        @"data" :[data base64EncodedString]
-    };
+    return @ {
+               @"CDVType" : @"ArrayBuffer",
+               @"data" :[data base64EncodedString]
+    }
 }
 
 id massageMessage(id message)
@@ -57,10 +57,10 @@ id messageFromMultipart(NSArray* theMessages)
         [messages replaceObjectAtIndex:i withObject:massageMessage([messages objectAtIndex:i])];
     }
 
-    return @{
-        @"CDVType" : @"MultiPart",
-        @"messages" : messages
-    };
+    return @ {
+               @"CDVType" : @"MultiPart",
+               @"messages" : messages
+    }
 }
 
 + (void)initialize
@@ -141,7 +141,7 @@ id messageFromMultipart(NSArray* theMessages)
 
 + (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageToErrorObject:(int)errorCode
 {
-    NSDictionary* errDict = @{@"code": [NSNumber numberWithInt:errorCode]};
+    NSDictionary* errDict = @ {@"code" :[NSNumber numberWithInt:errorCode]}
 
     return [[self alloc] initWithStatus:statusOrdinal message:errDict];
 }