Browse Source

add nullable qualifier to nil return types

Add the `nullable` qualifier to return types of Objective-C methods that
can return a nil due to errors. This change makes these methods
compatible with the Swift 2 try-catch syntax.
Dia Kharrat 9 years ago
parent
commit
523bfd4f23
2 changed files with 21 additions and 21 deletions
  1. 20 20
      objectivec/GPBMessage.h
  2. 1 1
      objectivec/Tests/GPBSwiftTests.swift

+ 20 - 20
objectivec/GPBMessage.h

@@ -97,7 +97,7 @@ CF_EXTERN_C_END
 ///                 the data can not be parsed.
 ///                 the data can not be parsed.
 ///
 ///
 /// @return A new instance of the class messaged.
 /// @return A new instance of the class messaged.
-+ (instancetype)parseFromData:(NSData *)data error:(NSError **)errorPtr;
++ (nullable instancetype)parseFromData:(NSData *)data error:(NSError **)errorPtr;
 
 
 /// Creates a new instance by parsing the data. This method should be sent to
 /// Creates a new instance by parsing the data. This method should be sent to
 /// the generated message class that the data should be interpreted as. If
 /// the generated message class that the data should be interpreted as. If
@@ -116,9 +116,9 @@ CF_EXTERN_C_END
 ///                          reason if the data can not be parsed.
 ///                          reason if the data can not be parsed.
 ///
 ///
 /// @return A new instance of the class messaged.
 /// @return A new instance of the class messaged.
-+ (instancetype)parseFromData:(NSData *)data
-            extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry
-                        error:(NSError **)errorPtr;
++ (nullable instancetype)parseFromData:(NSData *)data
+                     extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry
+                                 error:(NSError **)errorPtr;
 
 
 /// Creates a new instance by parsing the data from the given input stream. This
 /// Creates a new instance by parsing the data from the given input stream. This
 /// method should be sent to the generated message class that the data should
 /// method should be sent to the generated message class that the data should
@@ -137,10 +137,10 @@ CF_EXTERN_C_END
 ///                          reason if the data can not be parsed.
 ///                          reason if the data can not be parsed.
 ///
 ///
 /// @return A new instance of the class messaged.
 /// @return A new instance of the class messaged.
-+ (instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input
-                        extensionRegistry:
-                            (nullable GPBExtensionRegistry *)extensionRegistry
-                                    error:(NSError **)errorPtr;
++ (nullable instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input
+                                 extensionRegistry:
+                                     (nullable GPBExtensionRegistry *)extensionRegistry
+                                             error:(NSError **)errorPtr;
 
 
 /// Creates a new instance by parsing the data from the given input stream. This
 /// Creates a new instance by parsing the data from the given input stream. This
 /// method should be sent to the generated message class that the data should
 /// method should be sent to the generated message class that the data should
@@ -160,10 +160,10 @@ CF_EXTERN_C_END
 ///                          reason if the data can not be parsed.
 ///                          reason if the data can not be parsed.
 ///
 ///
 /// @return A new instance of the class messaged.
 /// @return A new instance of the class messaged.
-+ (instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input
-                                 extensionRegistry:
-                                     (nullable GPBExtensionRegistry *)extensionRegistry
-                                             error:(NSError **)errorPtr;
++ (nullable instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input
+                                          extensionRegistry:
+                                              (nullable GPBExtensionRegistry *)extensionRegistry
+                                                      error:(NSError **)errorPtr;
 
 
 /// Initializes an instance by parsing the data. This method should be sent to
 /// Initializes an instance by parsing the data. This method should be sent to
 /// the generated message class that the data should be interpreted as. If
 /// the generated message class that the data should be interpreted as. If
@@ -179,7 +179,7 @@ CF_EXTERN_C_END
 /// @param data     The data to parse.
 /// @param data     The data to parse.
 /// @param errorPtr An optional error pointer to fill in with a failure reason if
 /// @param errorPtr An optional error pointer to fill in with a failure reason if
 ///                 the data can not be parsed.
 ///                 the data can not be parsed.
-- (instancetype)initWithData:(NSData *)data error:(NSError **)errorPtr;
+- (nullable instancetype)initWithData:(NSData *)data error:(NSError **)errorPtr;
 
 
 /// Initializes an instance by parsing the data. This method should be sent to
 /// Initializes an instance by parsing the data. This method should be sent to
 /// the generated message class that the data should be interpreted as. If
 /// the generated message class that the data should be interpreted as. If
@@ -196,9 +196,9 @@ CF_EXTERN_C_END
 /// @param extensionRegistry The extension registry to use to look up extensions.
 /// @param extensionRegistry The extension registry to use to look up extensions.
 /// @param errorPtr          An optional error pointer to fill in with a failure
 /// @param errorPtr          An optional error pointer to fill in with a failure
 ///                          reason if the data can not be parsed.
 ///                          reason if the data can not be parsed.
-- (instancetype)initWithData:(NSData *)data
-           extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry
-                       error:(NSError **)errorPtr;
+- (nullable instancetype)initWithData:(NSData *)data
+                    extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry
+                                error:(NSError **)errorPtr;
 
 
 /// Initializes an instance by parsing the data from the given input stream. This
 /// Initializes an instance by parsing the data from the given input stream. This
 /// method should be sent to the generated message class that the data should
 /// method should be sent to the generated message class that the data should
@@ -216,10 +216,10 @@ CF_EXTERN_C_END
 /// @param extensionRegistry The extension registry to use to look up extensions.
 /// @param extensionRegistry The extension registry to use to look up extensions.
 /// @param errorPtr          An optional error pointer to fill in with a failure
 /// @param errorPtr          An optional error pointer to fill in with a failure
 ///                          reason if the data can not be parsed.
 ///                          reason if the data can not be parsed.
-- (instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input
-                       extensionRegistry:
-                           (nullable GPBExtensionRegistry *)extensionRegistry
-                                   error:(NSError **)errorPtr;
+- (nullable instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input
+                                extensionRegistry:
+                                    (nullable GPBExtensionRegistry *)extensionRegistry
+                                            error:(NSError **)errorPtr;
 
 
 /// Writes out the message to the given output stream.
 /// Writes out the message to the given output stream.
 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)output;
 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)output;

+ 1 - 1
objectivec/Tests/GPBSwiftTests.swift

@@ -446,7 +446,7 @@ class GPBBridgeTests: XCTestCase {
 
 
     let data = msg.data()
     let data = msg.data()
 
 
-    let msg2 = Message2(data: data!, error:nil)
+    let msg2 = try! Message2(data: data!)
     XCTAssertTrue(msg2 !== msg)  // New instance
     XCTAssertTrue(msg2 !== msg)  // New instance
     XCTAssertEqual(msg.optionalInt32, Int32(100))
     XCTAssertEqual(msg.optionalInt32, Int32(100))
     XCTAssertEqual(msg.optionalInt64, Int64(101))
     XCTAssertEqual(msg.optionalInt64, Int64(101))