Skip to content

Commit

Permalink
Merge pull request #92 from Snapchat/lf/revert-nsobject-in-protocols
Browse files Browse the repository at this point in the history
Make NSObject based protocols optional
  • Loading branch information
li-feng-sc authored Jul 10, 2022
2 parents 14c8aef + ca15c6c commit 7602165
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/source/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -202,6 +203,9 @@ object Main {
.text("Disable generating Objective-C class init helper method.")
opt[Boolean]("objc-closed-enums").valueName("<true/false>").foreach(x => objcClosedEnums = x)
.text("All generated Objective-C enums will be NS_CLOSED_ENUM (default: false). ")
opt[Boolean]("objc-strict-protocols")
.valueName("<true/false>").foreach(x => objcStrictProtocol = x)
.text("All generated @protocol will implement <NSObject> (default: true). ")
note("")
opt[File]("objcpp-out").valueName("<out-folder>").foreach(x => objcppOutFolder = Some(x))
.text("The output folder for private Objective-C++ files (Generator disabled if unspecified).")
Expand Down Expand Up @@ -416,6 +420,7 @@ object Main {
objcGenProtocol,
objcDisableClassCtor,
objcClosedEnums,
objcStrictProtocol,
wasmOutFolder,
wasmIncludePrefix,
wasmIncludeCppPrefix,
Expand Down
7 changes: 6 additions & 1 deletion src/source/ObjcGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 <NSObject>") else w.wl(s"@interface $self : NSObject")
if (useProtocol(i.ext, spec)) {
val baseProtocol = if (spec.objcStrictProtocol) " <NSObject>" 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)) {
Expand Down
1 change: 1 addition & 0 deletions src/source/generator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ package object generatorTools {
objcGenProtocol: Boolean,
objcDisableClassCtor: Boolean,
objcClosedEnums: Boolean,
objcStrictProtocol: Boolean,
wasmOutFolder: Option[File],
wasmIncludePrefix: String,
wasmIncludeCppPrefix: String,
Expand Down

0 comments on commit 7602165

Please sign in to comment.