• A strict superset of C
• Object oriented, but everything is NOT an object
• A dynamic runtime
• Static or dynamic typing for objects
!11
Objective-C
Slide 12
Slide 12 text
Modern Objective-C
• Object literals for arrays, hashes, numbers!
• Automatic memory management!!
• Enumeration with blocks!!!
• Domain specific languages!!!!
!12
Slide 13
Slide 13 text
A strict superset of C
Everything that works in C, works in Objective-C
• Control flow: if, while, for
• Primitive types, int, long, char, void *, const char *
• The C standard library
• UNIX system calls
!13
Slide 14
Slide 14 text
int n = 5;
const char *str = "hello, world\n";
unsigned long len = strlen(str);
!
if (len > 0) {
int i = 0;
while (i < n) {
printf("%s", str);
i++;
}
}
C
SEL selector = NSSelectorFromString(@"sayHello:inLanguage:");
Objective-C
!39
Slide 40
Slide 40 text
Objects
Slide 41
Slide 41 text
Objective-C
• Objects are all pointers
• But you (almost) never need to worry about that
• Just don’t forget the star, when declaring variables
or parameters
Slide 42
Slide 42 text
Foundation
• The “standard library” of Objective-C
• Objective-C doesn’t have proper namespaces
• We use 2 or 3 letters to prefix all class names to
prevent clashes
• For example, the Foundation framework that
defines strings, arrays, hashes etc. uses “NS”
• “NS” stands for “NeXTSTEP”
Prefixing classes
Slide 56
Slide 56 text
Duck typing and
introspection
Slide 57
Slide 57 text
Duck typing
When I see a bird that walks like a duck and swims like a
duck and quacks like a duck, I call that bird a duck.