Objective C Flashcards
Why can C programs be ran in O-C?
Objective C is a superset of C.
Similarities between Objective-C and C++
and differences
Object Orientation
Objective C has no function or operator overloading.
Objective-C:
C plus objects A strict superset of C C++ vs Objective-C: C++ : a better C O-C: a better way of soldering components together
Objective C frameworks:
2 OOP frameworks
Foundation: classes for basic data structures and interacting with OS
AppKit: classes for developing applications, windows, buttons, etc
Objective-C 2.0 adds
garbage collection <<< !!! syntax enhancements runtime performance improvements 64 bit support features such as properties and fast enumerators
Objective C class declaration
@interface SampleClass:NSObject
- (void) sampleMethod;
@end
Objective C class implementation
@implementation SampleClass
-(void) sampleMethod()
@end
What is #import
Bit like #include
Hello world
#import int main() { NSLog(@"Hello world!\n"); printf("%s\n", [@"Hello world!\n" UTF8String]); return 0; } printf understands UTF8.
Objective C code unit extension
.m
Wrapper classes
NSNumber int float double boolean NSString and NSMutableString unicode strings (usually UTF-16) NSArray and NSMutableArray dynamic arrays
Objects must always be:
pointers
i.e. NSNumber *num
Memory for objects is always allocated on the heap
Creating objects
NSNumber *num1
NSNumber *num2 = [NSNumber alloc]
NSNumber *num3a = [[NSNumber alloc] init]
NSNumber *num3b = [NSNumber new]
NSNumber *num4 = [[NSNumber alloc] initWithInteger:43]
^^^ num4 correct
What do all classes inherit from?
NSObject
Method declaration
-(void)setFirstName: (NSString *) name;