diff --git a/examples/generated-src/objc/TXSTextboxListener.h b/examples/generated-src/objc/TXSTextboxListener.h index 140eab31..d72c0661 100644 --- a/examples/generated-src/objc/TXSTextboxListener.h +++ b/examples/generated-src/objc/TXSTextboxListener.h @@ -5,7 +5,7 @@ #import -@protocol TXSTextboxListener +@protocol TXSTextboxListener - (void)update:(nonnull TXSItemList *)items; diff --git a/perftest/generated-src/objc/TXSObjectPlatform.h b/perftest/generated-src/objc/TXSObjectPlatform.h index 246f20f9..3521551c 100644 --- a/perftest/generated-src/objc/TXSObjectPlatform.h +++ b/perftest/generated-src/objc/TXSObjectPlatform.h @@ -5,7 +5,7 @@ /** interfaces for platform Java or Objective-C objects, to be passed to C++ */ -@protocol TXSObjectPlatform +@protocol TXSObjectPlatform - (void)onDone; diff --git a/src/source/Main.scala b/src/source/Main.scala index 49529053..a59b46cf 100644 --- a/src/source/Main.scala +++ b/src/source/Main.scala @@ -84,6 +84,7 @@ object Main { var objcppFunctionPrologueFile: Option[String] = None var objcppDisableExceptionTranslation: Boolean = false var objcFileIdentStyleOptional: Option[IdentConverter] = None + var objcStrictProtocol: Boolean = true var objcppNamespace: String = "djinni_generated" var objcBaseLibIncludePrefix: String = "" var wasmOutFolder: Option[File] = None @@ -202,6 +203,9 @@ object Main { .text("Disable generating Objective-C class init helper method.") opt[Boolean]("objc-closed-enums").valueName("").foreach(x => objcClosedEnums = x) .text("All generated Objective-C enums will be NS_CLOSED_ENUM (default: false). ") + opt[Boolean]("objc-strict-protocols") + .valueName("").foreach(x => objcStrictProtocol = x) + .text("All generated @protocol will implement (default: true). ") note("") opt[File]("objcpp-out").valueName("").foreach(x => objcppOutFolder = Some(x)) .text("The output folder for private Objective-C++ files (Generator disabled if unspecified).") @@ -416,6 +420,7 @@ object Main { objcGenProtocol, objcDisableClassCtor, objcClosedEnums, + objcStrictProtocol, wasmOutFolder, wasmIncludePrefix, wasmIncludeCppPrefix, diff --git a/src/source/ObjcGenerator.scala b/src/source/ObjcGenerator.scala index d9174dd6..79419b1c 100644 --- a/src/source/ObjcGenerator.scala +++ b/src/source/ObjcGenerator.scala @@ -135,7 +135,12 @@ class ObjcGenerator(spec: Spec) extends BaseObjcGenerator(spec) { w.wl writeDoc(w, doc) - if (useProtocol(i.ext, spec)) w.wl(s"@protocol $self") else w.wl(s"@interface $self : NSObject") + if (useProtocol(i.ext, spec)) { + val baseProtocol = if (spec.objcStrictProtocol) " " else "" + w.wl(s"@protocol $self$baseProtocol") + } else { + w.wl(s"@interface $self : NSObject") + } for (m <- i.methods) { if (!m.static || (!spec.objcGenProtocol && m.lang.objc)) { diff --git a/src/source/generator.scala b/src/source/generator.scala index 42526dde..5bd55f5a 100644 --- a/src/source/generator.scala +++ b/src/source/generator.scala @@ -88,6 +88,7 @@ package object generatorTools { objcGenProtocol: Boolean, objcDisableClassCtor: Boolean, objcClosedEnums: Boolean, + objcStrictProtocol: Boolean, wasmOutFolder: Option[File], wasmIncludePrefix: String, wasmIncludeCppPrefix: String, diff --git a/test-suite/generated-src/objc/DBAsyncInterface.h b/test-suite/generated-src/objc/DBAsyncInterface.h index ab6d81da..320068e0 100644 --- a/test-suite/generated-src/objc/DBAsyncInterface.h +++ b/test-suite/generated-src/objc/DBAsyncInterface.h @@ -5,7 +5,7 @@ #import -@protocol DBAsyncInterface +@protocol DBAsyncInterface - (nonnull DJFuture *)futureRoundtrip:(nonnull DJFuture *)f; diff --git a/test-suite/generated-src/objc/DBClientInterface.h b/test-suite/generated-src/objc/DBClientInterface.h index fcf20da9..64d7917d 100644 --- a/test-suite/generated-src/objc/DBClientInterface.h +++ b/test-suite/generated-src/objc/DBClientInterface.h @@ -7,7 +7,7 @@ /** Client interface */ -@protocol DBClientInterface +@protocol DBClientInterface /** Returns record of given string */ - (nonnull DBClientReturnedRecord *)getRecord:(int64_t)recordId diff --git a/test-suite/generated-src/objc/DBEnumUsageInterface.h b/test-suite/generated-src/objc/DBEnumUsageInterface.h index 68493c21..d0f8400f 100644 --- a/test-suite/generated-src/objc/DBEnumUsageInterface.h +++ b/test-suite/generated-src/objc/DBEnumUsageInterface.h @@ -5,7 +5,7 @@ #import -@protocol DBEnumUsageInterface +@protocol DBEnumUsageInterface - (DBColor)e:(DBColor)e; diff --git a/test-suite/generated-src/objc/DBExternInterface2.h b/test-suite/generated-src/objc/DBExternInterface2.h index 59f4f6e7..8ffff680 100644 --- a/test-suite/generated-src/objc/DBExternInterface2.h +++ b/test-suite/generated-src/objc/DBExternInterface2.h @@ -6,7 +6,7 @@ #import -@protocol DBExternInterface2 +@protocol DBExternInterface2 - (nonnull DBExternRecordWithDerivings *)foo:(nullable DBTestHelpers *)i; diff --git a/test-suite/generated-src/objc/DBFirstListener.h b/test-suite/generated-src/objc/DBFirstListener.h index f660d649..9c338a0b 100644 --- a/test-suite/generated-src/objc/DBFirstListener.h +++ b/test-suite/generated-src/objc/DBFirstListener.h @@ -5,7 +5,7 @@ /** Used for ObjC multiple inheritance tests */ -@protocol DBFirstListener +@protocol DBFirstListener - (void)first; diff --git a/test-suite/generated-src/objc/DBObjcOnlyListener.h b/test-suite/generated-src/objc/DBObjcOnlyListener.h index b344bd00..673386c4 100644 --- a/test-suite/generated-src/objc/DBObjcOnlyListener.h +++ b/test-suite/generated-src/objc/DBObjcOnlyListener.h @@ -4,6 +4,6 @@ #import -@protocol DBObjcOnlyListener +@protocol DBObjcOnlyListener @end diff --git a/test-suite/generated-src/objc/DBSecondListener.h b/test-suite/generated-src/objc/DBSecondListener.h index c35985db..4b2b1870 100644 --- a/test-suite/generated-src/objc/DBSecondListener.h +++ b/test-suite/generated-src/objc/DBSecondListener.h @@ -5,7 +5,7 @@ /** Used for ObjC multiple inheritance tests */ -@protocol DBSecondListener +@protocol DBSecondListener - (void)second; diff --git a/test-suite/generated-src/objc/DBUserToken.h b/test-suite/generated-src/objc/DBUserToken.h index 38ad4952..23a9d08e 100644 --- a/test-suite/generated-src/objc/DBUserToken.h +++ b/test-suite/generated-src/objc/DBUserToken.h @@ -4,7 +4,7 @@ #import -@protocol DBUserToken +@protocol DBUserToken - (nonnull NSString *)whoami; diff --git a/test-suite/generated-src/objc/DBUsesSingleLanguageListeners.h b/test-suite/generated-src/objc/DBUsesSingleLanguageListeners.h index 51e55596..e2dc7291 100644 --- a/test-suite/generated-src/objc/DBUsesSingleLanguageListeners.h +++ b/test-suite/generated-src/objc/DBUsesSingleLanguageListeners.h @@ -10,7 +10,7 @@ * Generating and compiling this makes sure other languages don't break * on references to interfaces they don't need. */ -@protocol DBUsesSingleLanguageListeners +@protocol DBUsesSingleLanguageListeners - (void)callForObjC:(nullable id)l;