I'm trying to convert a Java code to Objective-C. The class below is the extension of TestCodeRequest. Wondering how to convert this to an objective C equivalent. I'm finding it a bit confusing because Java is statically typed, and configuration over convention. Whereas Objective-C is dynamically typed, and convention over configuration. I have a sample code below. Any small hint should be really great.
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);
}
}
There are several good Java to Objective C translators. For code that simple, all of them should work. Where translators usually have a lot of trouble is translating calls to runtime libraries because of their divergent philosophies (especially in the area of look-and-feel and user interaction). To do a good job here, they need to go from syntax back to semantics, and this is extremely difficult for software to do.
Your phrase "Java is statically typed, and configuration over convention. Whereas Objective-C is dynamically typed, and convention over configuration" can't but refer to this. Specifically GUI development. This aspect of the languages is not intrinsic to them, but belongs to the libraries that developers usually employ, in many cases dependent on specific Operating Systems. So, we are probably not talking as much about converting Java to Objective C as of converting from a Swing look-and-feel and mode of interaction to an iOS one.
All considered, I'd recommend you to use automatic conversion tools as learning tools. You will see that the generated pieces of code (as they become more complex and/or incorporate user interfaces) even if they work, are not suitable for maintenance or further development and need to be re-coded if not redesigned. But again, as learning tools they are very useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With