0 Comments

Despite Swift’s dominance, Objective-C remains crucial for maintaining legacy iOS/macOS apps. Over 20% of existing iOS apps still use Objective-C, making it a valuable skill for developers working with older codebases at companies like Apple, Facebook, and Bloomberg.

This comprehensive guide covers:

  • Core Objective-C concepts
  • Memory management
  • Runtime features
  • Comparison with Swift
  • Common pitfalls

30 Essential Objective-C Interview Questions

1. What is Objective-C and why is it still used?

Answer:
Objective-C is:

  • superset of C with Smalltalk-style messaging
  • The original language for macOS/iOS development
  • Still used for:
    • Maintaining legacy apps
    • Interoperating with Swift via bridging
    • Low-level performance-critical code

2. Explain the difference between #import and #include

Answer:

objective-c

Copy

Download

#import "Header.h"  // Prevents duplicate inclusions (recommended)
#include "Header.h" // May cause duplicates (C-style)

3. What are categories in Objective-C?

Answer:
Categories add methods to existing classes without subclassing:

objective-c

Copy

Download

@interface NSString (MyCategory)
- (BOOL)isValidEmail;
@end

4. How does message passing work in Objective-C?

Answer:
Unlike C++’s direct method calls, Objective-C uses dynamic dispatch:

objective-c

Copy

Download

[object message:param]; // Compiled to objc_msgSend(object, @selector(message:), param)

5. What is the difference between atomic and nonatomic properties?

Answer:

AtomicNonatomic
Thread-safe (slower)Not thread-safe (faster)
Default for @propertyCommon in iOS development

Memory Management

6. Explain Manual Retain-Release (MRR) vs ARC

Answer:

objective-c

Copy

Download

// MRR (pre-2011)
NSObject *obj = [[NSObject alloc] init]; // retainCount = 1
[obj retain]; // retainCount = 2
[obj release]; // retainCount = 1

// ARC (automatic)
NSObject *obj = [[NSObject alloc] init]; // Compiler inserts releases

7. What is a retain cycle and how do you break it?

Answer:
Occurs when two objects hold strong references to each other. Solutions:

objective-c

Copy

Download

@property (weak) id delegate; // Use weak for delegates
__weak typeof(self) weakSelf = self; // In blocks

Runtime Features

8. What is the Objective-C runtime?

Answer:
A C library that enables:

  • Dynamic method resolution
  • Method swizzling
  • Introspection (class inspection at runtime)

9. How would you implement method swizzling?

Answer:

objective-c

Copy

Download

Method original = class_getInstanceMethod([self class], @selector(viewDidLoad));
Method swizzled = class_getInstanceMethod([self class], @selector(swizzled_viewDidLoad));
method_exchangeImplementations(original, swizzled);

Comparison with Swift

10. Compare Objective-C protocols vs Swift protocols

Answer:

FeatureObjective-CSwift
Optional methodsYesNo (use @objc)
Protocol extensionsNoYes
Associated typesNoYes

Advanced Concepts

11. What are class clusters?

Answer:
A design pattern where a public abstract class (e.g., NSArray) hides private concrete subclasses:

objective-c

Copy

Download

NSArray *arr = @[@1, @2]; // Actually creates __NSArrayI

12. Explain toll-free bridging

Answer:
Seamless casting between Core Foundation and Foundation types:

objective-c

Copy

Download

CFArrayRef cfArray = (__bridge CFArrayRef)nsArray;
NSArray *nsArray = (__bridge NSArray*)cfArray;

People Also Ask

Q1: Is Objective-C dead in 2024?

A: No! While Swift is preferred for new projects, Objective-C is still maintained and used in:

  • Legacy codebases (e.g., banking apps)
  • Low-level frameworks
  • Projects requiring C interoperability

Q2: Should I learn Objective-C or Swift first?

A: Learn Swift first for new projects, but Objective-C is valuable for:

  • Maintaining older apps
  • Understanding Apple’s legacy APIs
  • Working with mixed codebases

Q3: What’s the salary for Objective-C developers?

A: In the US:

  • Junior: 85K–85K–120K
  • Senior: 130K–130K–200K
  • Legacy system specialists: Up to $250K

Q4: How do Objective-C and Swift interoperate?

A: Through:

  • Bridging headers (MyProject-Bridging-Header.h)
  • @objc annotations in Swift
  • Framework targets with DEFINES_MODULE = YES

Conclusion

Mastering Objective-C interview questions requires understanding:

  1. Memory management (ARC vs MRR)
  2. Runtime features (method swizzling, messaging)
  3. Legacy patterns (class clusters, categories)
  4. Swift interoperability

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts