Search code examples
javaobjective-cswiftj2objc

J2ObjC: translating @Nullable to __nullable


I'm trying to translate Java nullability annotations to Objective-C to get Optionals in Swift but nothing happens, the signature of the methods remains the same.

Here is the Java code:

import javax.annotation.Nullable;
import com.google.j2objc.annotations.ObjectiveCName;

public class UserValidation {
    @Nullable
    @ObjectiveCName(value = "getFormattedUserId:")
    public static String getFormattedUserId(@Nullable String userId) {}
}

When traslated I get:

+ (NSString *)getFormattedUserId:(NSString *)userId;

instead of:

+ (NSString * __nullable)getFormattedUserId:(NSString * __nullable)userId;

I want this signature sin Swift:

class func getFormattedUserId(userId: String?) -> String?

What I'm doing wrong?

Thank you so much.


Solution

  • The answer in the comment by @tball is correct, it worked adding the --nullability flag, with the latest sources, not the latest release.

    More information here.

    Thanks Tom.