Day-4 Flashcards

1
Q

Composite Objects

A

A way to extend the definition of a class from one or more objects from other classes.

When you define a subclass, it inherits all the instance variables and methods of the parent class. In some cases, this is undesirable.

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

Retain Cycles

A

A retain cycle happens when two objects have strong references to each other.

A weak reference is a non-owning relationship where the source object does not retain the object to which it has a reference

Since blocks and closures capture strong references to all objects accessed in their bodies, if the object represented by self were to get a strong pointer to the block or closure, then we would have a retain cycle

Weak : Outlets, Self to use inside blocks.

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

Key Value Coding

A

NSKeyValueCoding : A protocol that defines mechanisms for indirectly accessing object properties

We access them with the “Key Path”

  • (void)setValue:(id)value forKey:(NSString *)key;
  • (id)valueForKey:(NSString *)key;

// Typical

self. name = @”Adam”;
self. email = @”me@me.com”;

// KVC
[self setValue:@”Adam” forKey:@”name”];
[self setValue:@”me@me.com” forKey:@”email”];

// KVC, Two properties deep.

NSNumber *length = [self valueForKeyPath:@”name.length”];

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

KVO

A

Alternative to ( didSet and willSet in Swift )

Another protocol. It is considered informal, meaning you wont see it advertised in the docs when objects conform, because NSObject is assumed to conform to it

Object properties can be observed indirectly by their key

addObserver:forKeyPath:options:context
observeValueForKeyPath:ofObject:change:context

If you mutate properties outside of the generated setter, you’ll need to call these methods manually to be KVO compliant:

  • (void)willChangeValueForKey:(NSString *)key;
  • (void)didChangeValueForKey:(NSString *)key;

New - check the new value from the observer
Old - check the previous value from the observer

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

KVO Gotchas

A

The concept to remove the observer so we can tell if we have an observer..
http://www.appcoda.com/understanding-key-value-observing-coding/

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

Memory Management

A

Memory management is all about cleaning up unused memory so that it can be used again

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

Strong Vs. Weak

A

Strong increment the retain count in the memory, which means the memory will hold on to that pointer.
(@property is important to not lose in the app so it’s Strong)

Weak is used to point at something but doesn’t use the memory to hold on to it.
(@outlet is weak because what if the storyboard is gone? the reference to the label or UIText will have no meaning staying there in code).

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

ARC (important subject for interviews)

A

ARC eliminates all the potential pitfalls associated with manual reference counting. Under the hood, reference counts are still being maintained and tracked. However, the system determines when to retain an object and when to autorelease or release it

By default, all object pointer variables are strong variables
The old object reference will be released before the assignment is made
Strong variables are initialized to zero by default
Weak variables references are used to avoid retain cycles and memory leaks

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

Turn off the MRC (memory reference code) manually

A

Turn off the Arc:

1) create a file as Cocoa touch with their subclass
2) go to the application “Build Phases menu” then Compile Sources
4) type in “-fno-objc-arc” in the file we just created and want to disable

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