Java
Your class is in a single file in Java and you define the methods in the file MyClass.java.
So in Java we have:
public class MyClass {
public String myMethod() {
return "";
}
}
You call a function in Java as in:
myObject.addObject(anotherObject);
If you try to invoke a method on a null reference, you will get a NullPointerException in Java.
Objective C
In Objective C each class file is divided into a public header file MyClass.h and a private implementation file MyClass.m.
In Objective C we have:
MyClass.h
@interface MyClass : NSObject {
}
-(NSString*)myMethod:(id)sender;
@end
MyClass.m
@implementation MyClass
-(NSString*)myMethod:(id)sender {
return @""; // string literal
}
@end
You send a message to an object in Objective C. The syntax for sending a message in Objective C is sufficiently unique to identify the syntax as NOT-C, but a superset of C as in:
[myObject addObject: anotherObject]
It is OK to send a message to nil in Objective C, so [myString length] returns 0 if myString is nil.
In iOS you can forward class declarations in the header files to minimize circular declarations as in UIViewController.h:
#import <UIKit/UIKit.h>
@class Model; // declared forwarded class
and import Model.h in UIViewController.h:
#import "EncryptSMSViewController.h"
#import "Model.h"