Objective C Translation

So I’ve spent the last week or so translating the server interaction code from Objective C to Java.  Since Objective C is just a superset of C, I didn’t think it would be too difficult.  Of course I should have realized this was not the case since I was translating classes (aka the reason for Objective C).  The syntax for Objective C had a far greater learning curve than I had expected, although it gets easier the more you work with it.

Here are a few things I discovered along the way:

  • Almost all Objective C data types exist in Java if you remove the preceding NS.  For example: NSString -> String, NSUrlConnection -> UrlConnection, etc.
  • When Objective C says id, it means Object.
  • Ternary operator syntax is the same (yay!).
  • + represents class methods.  represents instance methods.  (Obvious right?)
  • Calling a method looks like this: [ object method:arg1 argument2:arg2 ]
  • @ appears in front of Objective C reserved words (an easy way to avoid conflicts between C and Objective C during compilation).  It also appears in front of string literals, for example @”Hello”.
  • Objective C BOOL uses YES and NO
  • Memory management exists in Objective C.


Filed under Tetherless World Constellation, Wine Agent

3 responses to “Objective C Translation

  1. Pingback: Status Update | souzada

  2. In calling the method, the : after object shouldn’t be there, I think. I find it interesting that even classes like UrlConnection are the same between them without the NS, I wouldn’t have expected that. Was it annoying translating the delegate/protocol stuff across, or did you not encounter that?

    • There were a fair amount of objects (like NSUrlResponse) which weren’t there and of course NSUrlConnection and UrlConnection aren’t exactly the same, but they are functionality similar enough for it to work.

      Translating the delegate/protocol stuff was annoying but it wasn’t awful since it’s possible to define methods of an interface inline.

      Oh and you were right about the colon. Thanks for pointing that out.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s