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.