What Interviewers Actually Probe For
Objective-C interviews rarely test whether you've memorized every Foundation class; they test whether you understand the runtime concepts that cause real production bugs: reference counting and retain cycles, the difference between class and instance methods, protocol conformance, and block capture semantics. Strong candidates explain not just what a mechanism does but why it exists and what specific bug it prevents, because that's the signal that the knowledge came from real debugging experience rather than rote memorization.
Cricket analogy: A strong interview answer explaining why a retain cycle happens is like a commentator explaining why a batsman got out, not just that the stumps were hit, but the exact technical flaw in the shot selection that led there.
Memory Management Questions
A frequent question is 'explain what causes a retain cycle and how you'd fix it,' expecting the candidate to describe two objects holding strong references to each other, such as a parent view controller and a block property that captures self strongly, preventing either from ever reaching a retain count of zero. The correct fix involves either declaring one side weak, most commonly the delegate or the block's captured self, or using a capture list like __weak typeof(self) weakSelf = self; inside the block to break the cycle.
Cricket analogy: A retain cycle between a view controller and its block is like two batsmen both refusing to run for a single, each waiting for the other to commit first, until a __weak reference acts like a decisive call that finally breaks the standoff.
// Classic retain cycle
@interface ImageLoader : NSObject
@property (nonatomic, copy) void (^completion)(UIImage *image);
@end
@implementation ViewController
- (void)loadImage {
self.loader.completion = ^(UIImage *image) {
self.imageView.image = image; // captures self strongly -> cycle
};
}
// Fix: weak-strong dance
- (void)loadImageFixed {
__weak typeof(self) weakSelf = self;
self.loader.completion = ^(UIImage *image) {
__strong typeof(weakSelf) strongSelf = weakSelf;
if (!strongSelf) return;
strongSelf.imageView.image = image;
};
}
@endThe 'weak-strong dance' — capturing a weak reference, then promoting it to a strong local reference inside the block body — is a standard, interview-worthy pattern because it avoids both the retain cycle and a crash if self is deallocated mid-execution of the block.
Runtime, Protocols, and Blocks
Interviewers often ask about the difference between a protocol and a category: a protocol declares a contract of methods a conforming class must implement, similar to an interface, while a category adds new methods to an existing class, including classes you don't own, without subclassing. A related favorite is explaining how a block captures variables: local variables are captured by value (a snapshot at block-creation time) while __block-qualified variables are captured by reference, allowing the block to actually mutate the original variable's storage.
Cricket analogy: A protocol is like a fielding position's job description, whoever stands at cover must be ready to field and throw, while a category is like adding a new specialized skill, say reverse-sweep coaching, to an existing veteran player without replacing them.
A common interview trap: candidates confuse a category with a class extension. A category is declared with a name in parentheses (e.g., @interface NSString (MyAdditions)) and can be used to add methods from anywhere, including in a separate file, whereas a class extension (an unnamed category, typically at the top of the .m file) can only be used within the same compilation unit and can add private properties, which regular categories cannot do.
- Interviewers value understanding why a mechanism exists and what bug it prevents, not just its definition.
- A retain cycle occurs when two objects hold strong references to each other, most commonly a block capturing self strongly.
- The weak-strong dance (__weak then __strong inside the block) is the standard fix for block-related retain cycles.
- A protocol declares a method contract a class must implement; a category adds methods to an existing class without subclassing.
- Local variables are captured by value in a block; __block-qualified variables are captured by reference and can be mutated.
- A class extension (unnamed category) can add private properties and is scoped to the same compilation unit, unlike a regular named category.
- Explaining concrete debugging scenarios, not just definitions, is what distinguishes strong candidates in Objective-C interviews.
Practice what you learned
1. What commonly causes a retain cycle involving blocks in Objective-C?
2. What is the standard fix known as the 'weak-strong dance'?
3. What is the key difference between a protocol and a category?
4. How are ordinary local variables captured inside an Objective-C block by default?
5. What can a class extension do that a regular named category cannot?
Was this page helpful?
You May Also Like
Objective-C Best Practices
Practical, battle-tested conventions for writing safe, readable, and maintainable Objective-C code, from memory management to naming and API design.
Objective-C Quick Reference
A condensed reference for Objective-C syntax, common Foundation types, memory attributes, and idioms you'll reach for constantly while coding.
Objective-C vs Swift
A practical comparison of Objective-C and Swift covering syntax, memory management, interoperability, and when each language is the right choice on Apple platforms.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics