diff --git a/compiler/src/main/java/com/readdle/codegen/SwiftFuncDescriptor.java b/compiler/src/main/java/com/readdle/codegen/SwiftFuncDescriptor.java index 7b58bc6..8ec4420 100644 --- a/compiler/src/main/java/com/readdle/codegen/SwiftFuncDescriptor.java +++ b/compiler/src/main/java/com/readdle/codegen/SwiftFuncDescriptor.java @@ -116,7 +116,21 @@ public void generateCode(SwiftWriter swiftWriter, String javaFullName, String sw swiftWriter.emitStatement(String.format("let %s: %s%s", param.name, param.swiftType.swiftType, param.isOptional ? "?" : "")); } - boolean shouldCatchPreamble = params.size() > 0 || !isStatic; + + boolean shouldCatchPreamble = false; + if (isStatic) { + for (SwiftParamDescriptor param : params) { + // primitive types constructors not throw + if (param.isOptional || !param.isPrimitive()) { + shouldCatchPreamble = true; + break; + } + } + } + else { + shouldCatchPreamble = true; + } + if (shouldCatchPreamble) { swiftWriter.emitStatement("do {"); }