0

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.

emenegro
  • 6,901
  • 10
  • 45
  • 68
  • How exactly are you doing the translating? Presumably some program ... surely this program has options and configuration? Maybe you should tell us a bit more about what you're doing. – dcsohl Jan 11 '16 at 15:28
  • j2objc, sorry, I put the tag but nothing more. I edit the question. – emenegro Jan 11 '16 at 15:29
  • 1
    Didn't include the --nullability flag? Or maybe looking at the .m file instead of the header? $ j2objc -q -classpath ~/jars/jsr305.jar --nullability UserValidation.java $ grep nullable UserValidation.h + (NSString * __nullable)getFormattedUserId:(NSString * __nullable)userId; – tball Jan 11 '16 at 16:59

1 Answers1

0

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.

emenegro
  • 6,901
  • 10
  • 45
  • 68