Convert Java to Objective C

I am trying to convert Java code to Objective-C. The next class is the TestCodeRequest extension. I wonder how to convert this to an objective C-equivalent. I find this a bit confusing because Java is statically typed and configured by convention. While Objective-C is dynamically typed and conditionally configured. I have an example code below. Any little hint should be really big.

package com.TestCode.api; import java.io.IOException; import oauth.signpost.exception.OAuthCommunicationException; import oauth.signpost.exception.OAuthExpectationFailedException; import oauth.signpost.exception.OAuthMessageSignerException; import org.json.JSONObject; public class Categories extends TestCodeRequest { public Categories(String apiKey, String apiSecret) { super(apiKey, apiSecret, "categories"); } public Categories field(Object... fields) { super.field(fields); return this; } public JSONObject getCategories() throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, IOException { return this.get(); } public Categories categoriesField(Object... fields) { return this.field(fields); } } 
+6
source share
1 answer

There are some good Java translators in Objective-C. For code that is simple, they should all work. Where translators tend to have a lot of problems, this is transferring calls to runtime libraries due to their diverging philosophies (especially in the area of โ€‹โ€‹appearance and user interaction). To do a good job here, they need to move from syntax to semantics, and this is very difficult for software.

Your phrase "static Java typing and convention by convention. While Objective-C is dynamically typed and convention by convention" cannot but refer to this. In particular, the development of a graphical interface. This aspect of languages โ€‹โ€‹is not an integral part for them, but it belongs to the libraries that developers usually use, in many cases depending on specific operating systems. Thus, we are probably not talking so much about converting Java to Objective-C, as about converting from Swing style and how it interacts in iOS.

All reviewed, I would recommend using automatic conversion tools as training tools. You will see that the generated code fragments (as they become more complex and / or include user interfaces), even if they work, are not suitable for maintenance or further development and require re-encoding if they are not processed. But then again, as training tools, they are very useful.

  • Google J2ObjC
  • java2objc
  • JCGO This one is converted to C. If the goal is to work something, it can be good enough. Not if the goal is to learn Objective-C in all its splendor.
+11
source

Source: https://habr.com/ru/post/952375/


All Articles