-1

j2objc created a class method declaration in the header file as follows:

(void)startWithNSString:(NSString *)folderPath
    withNSString:(NSString *)pushyToken
    withInt:(jint)port
    withInt:(jint)width
    withInt:(jint)height

I am trying to call this from swift code.

Could anybody direct to me on how to do.

EDIT#1:

Matt, I added the labels as follows:

    let screenSize = UIScreen.main.bounds
    let screenWidth:Int32 = Int32(screenSize.width)
    let screenHeight:Int32 = Int32(screenSize.height)

    let pushyToken = UserDefaults.standard.object(forKey: "pushyToken") as? String ?? String()
    SocketClient.startWithNSString("", withNSString:pushyToken,
                                         withInt:8000, withInt:screenWidth, withInt:screenHeight)

I am getting error:

'startWithNSString(_:withNSString:withInt:withInt:withInt:)' has been renamed to 'start(with:with:with:with:with:)'

Sharad Chauhan
  • 4,821
  • 2
  • 25
  • 50
user3911119
  • 273
  • 3
  • 14
  • That is really hard to tell without knowing what it will substitute for `jint`, but generally you will probably have troubles calling the methods if two parameters have the same name (before the colon). Anyways, you should post your error message (I guess you will get one from the compiler). If you are using something like `j2objc` it might be advisable to look for `j2swift` in the first place ... – Patru Jul 17 '18 at 02:43
  • ok... apologies for the obfuscation. def is a folder path, ghi a pushy token, jkl is a port number, mno and pqr are screen width and height. Because of unfamiliarity with both Objective C and Swift, I am not able to get anything right and it is an error everytime. I could not find anything on net which I could use to learn by example. I have a complex java library that needs translation. Can j2swift handle it? – user3911119 Jul 17 '18 at 03:03
  • Explain what a `jint` is. – matt Jul 17 '18 at 03:19
  • The error message is clear: "Missing argument labels 'withNSString:withInt:withInt:withInt:' in call" Put in the labels! But also explain what a `jint` is. – matt Jul 17 '18 at 03:20
  • jint is a C type defined in JNI (I guess signed 32). It came when java code was translated to Objective C. – user3911119 Jul 17 '18 at 03:26
  • I hope annotating the Int32 might help you in this regard. As `let screenWidth:Int32` – nayem Jul 17 '18 at 03:48
  • added the annotation... have updated the post. Now, it is a new problem :(. – user3911119 Jul 17 '18 at 03:49
  • The public interface is updated to the new signature of the method. You just use what it suggests. – nayem Jul 17 '18 at 03:50
  • thanks ! that worked. – user3911119 Jul 17 '18 at 07:46
  • Yes, [jint is an int32_t](https://github.com/google/j2objc/blob/master/jre_emul/Classes/J2ObjC_types.h#L30). – tball Jul 17 '18 at 15:39

1 Answers1

1

This is what Xcode 9 give me in the auto complete:

object.abc(with: "Folder path", with: "Token", with: portNumber, with: width, with: height)

Assuming you have variables called portNumber, width and height of the appropriate type in Swift. (Are they all integers?)

Code Different
  • 90,614
  • 16
  • 144
  • 163