Objective-C Flashcards

1
Q

How do you access a Selector?

A

There are two ways to get the selector for a method name. The @selector() directive lets you convert a source-code method name to a selector, and the NSSelectorFromString() function lets you convert a string to a selector (the latter is not as efficient). Both of these return a special data type for selectors called SEL. You can use SEL the exact same way as BOOL, int, or any other data type.

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

What is a Pointer?

A

A variable that is able to store the address of another variable is called a “pointer”. This is because the variable is said to point to the location of another value. The following code snippet demonstrates how we can use the address-of “&“operator:

int x = 45;
int* y = &x;

This code snippet declares an integer variable x that is initialized to the value 45. It also declares variable y with a data type of int*. The * at the end of the data type indicates a pointer and means we do not want to store an actual integer value but rather the memory address at which one can be found. This pointer is then initialized with the address of variable x using the address-of operator. If variable x had been stored at address 928 (as previously mentioned), we could graphically represent the result of executing this code snippet by updating the memory map to be similar to that in Figure 2.

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

What is a Selector?

A

Selectors are Objective-C’s internal representation of a method name. They let you treat a method as an independent entity, enabling you to separate an action from the object that needs to perform it. This is the basis of the target-action design pattern, It’s also an integral part of Objective-C’s dynamic typing system.

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