Objective C Flashcards

1
Q

Why can C programs be ran in O-C?

A

Objective C is a superset of C.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Similarities between Objective-C and C++

and differences

A

Object Orientation

Objective C has no function or operator overloading.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Objective-C:

A
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Objective C frameworks:

A

2 OOP frameworks
Foundation: classes for basic data structures and interacting with OS
AppKit: classes for developing applications, windows, buttons, etc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Objective-C 2.0 adds

A
garbage collection <<< !!!
syntax enhancements
runtime performance improvements
64 bit support
features such as properties and fast enumerators
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Objective C class declaration

A

@interface SampleClass:NSObject
- (void) sampleMethod;
@end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Objective C class implementation

A

@implementation SampleClass
-(void) sampleMethod()
@end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is #import

A

Bit like #include

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Hello world

A
#import 
int main()
{
     NSLog(@"Hello world!\n");
     printf("%s\n", [@"Hello world!\n" UTF8String]);
     return 0;
}
printf understands UTF8.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Objective C code unit extension

A

.m

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Wrapper classes

A
NSNumber
int float double boolean
NSString and NSMutableString
unicode strings (usually UTF-16)
NSArray and NSMutableArray
dynamic arrays
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Objects must always be:

A

pointers
i.e. NSNumber *num
Memory for objects is always allocated on the heap

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Creating objects

A

NSNumber *num1
NSNumber *num2 = [NSNumber alloc]
NSNumber *num3a = [[NSNumber alloc] init]
NSNumber *num3b = [NSNumber new]
NSNumber *num4 = [[NSNumber alloc] initWithInteger:43]
^^^ num4 correct

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What do all classes inherit from?

A

NSObject

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Method declaration

A

-(void)setFirstName: (NSString *) name;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
  • vs +
A
- instance method
\+ class method (static)
17
Q

Memory allocation

A

C malloc, free (from heap)
C++ new, delete
O-C, constructors name begins with init, called after alloc i.e. [[NSNumber alloc] initWithInteger:@43];

18
Q

What is id

A

Datatype that is a pointer to any type of object
Supports dynamic referencing, object type defined at runtime.
(id) init
(Money *) init