Top 50 Objective-c Interview Questions with Answers

Objective-c Interview Questions with Answers

1. What is Objective-C?


A. A programming language
B. A database management system
C. A web development framework

Answer: A

2. Who developed Objective-C?

A. Apple
B. Google
C. Microsoft

Answer: A

3. Which of the following is a feature of Objective-C?

A. Dynamic binding
B. Type safety
C. Both of the above

Answer: C

4. Objective-C is based on which programming language?

A. C
B. Java
C. Python

Answer: A

5. What is dynamic typing in Objective-C?

A. The type of a variable is determined at compile time
B. The type of a variable is determined at runtime
C. There is no typing in Objective-C

Answer: B

6. Which of the following is a data type in Objective-C?

A. Int
B. Float
C. Both of the above

Answer: C

7. Which of the following is a control structure in Objective-C?

A. If-else
B. Switch-case
C. Both of the above

Answer: C

8. What is the syntax for creating an array in Objective-C?

A. int array[] = {1, 2, 3};
B. NSArray *array = @[1, 2, 3];
C. ArrayList> array = new ArrayList>({1, 2, 3});

Answer: B

9. What is the syntax for creating a dictionary in Objective-C?

A. NSDictionary *dict = @{@”key1″: @”value1″, @”key2″: @”value2″};
B. Map, String> dict = new HashMap<>(){{“key1”, “value1”}, {“key2”, “value2”}};
C. Dictionary dict = Dictionary.create({{“key1”, “value1”}, {“key2”, “value2”}});

Answer: A

10. What is the syntax for creating a method in Objective-C?

A. -(void)methodName;
B. void methodName();
C. function methodName();

Answer: A

11. Which of the following is the correct way to call a method in Objective-C?

A. [object methodName];
B. object.methodName;
C. object->methodName;

Answer: A

12. Which of the following is the correct syntax for defining a class in Objective-C?

A. class MyClass {}
B. @interface MyClass : NSObject {}
C. public class MyClass {}

Answer: B

13. What is the purpose of @synthesize in Objective-C?

A. It creates a setter and getter for a property
B. It creates a constructor for a class
C. It creates a static variable

Answer: A

14. What is the purpose of @protocol in Objective-C?

A. It defines a set of methods that a class must implement
B. It defines a set of properties that a class must have
C. It defines a set of constants that a class must use

Answer: A

15. What is the purpose of @optional in an Objective-C protocol?

A. It specifies that a method is not required to be implemented by a class
B. It specifies that a property is not required to be present in a class
C. It specifies that a constant is not required to be used by a class

Answer: A

16. What is the purpose of @required in an Objective-C protocol?

A. It specifies that a method must be implemented by a class
B. It specifies that a property must be present in a class
C. It specifies that a constant must be used by a class

Answer: A

17. What is a category in Objective-C?

A. It is a way to add methods to an existing class
B. It is a way to define a new class
C. It is a way to encapsulate data

Answer: A

18. What is a block in Objective-C?

A. It is a way to define a method that can be passed as an argument to another method
B. It is a way to define an instance variable
C. It is a way to define a constant

Answer: A

19. What is the purpose of ARC in Objective-C?

A. It automatically manages memory for objects
B. It automatically manages memory for variables
C. It automatically manages memory for methods

Answer: A

20. What is the syntax for creating a property in Objective-C?

A. @property (nonatomic, strong) NSString *name;
B. property String name = new String();
C. String name = new String(property);

Answer: A

21. What is the difference between nonatomic and atomic in Objective-C property declaration?

A. nonatomic means that the property is not thread safe
B. atomic means that the property is thread safe
C. Both of the above

Answer: B

22. Which of the following is a way to specify the access level of a property in Objective-C?

A. public
B. private
C. readonly

Answer: C

23. What is the purpose of the @synthesize directive?

A. It allows you to manually specify the name of the generated getter and setter methods
B. It automatically generates getter and setter methods for the property
C. It has no purpose in Objective-C

Answer: B

24. What is the difference between a synthesized and dynamic property in Objective-C?

A. A synthesized property has getter and setter methods automatically generated by the compiler, whereas a dynamic property must be implemented manually
B. A dynamic property has getter and setter methods automatically generated by the compiler, whereas a synthesized property must be implemented manually
C. There is no difference between a synthesized and dynamic property

Answer: A

25. How would you create a class method in Objective-C?

A. +(void)methodName;
B. void methodName();
C. function methodName();

Answer: A

26. How would you call a class method in Objective-C?

A. [ClassName methodName];
B. ClassName->methodName();
C. ClassName::methodName();

Answer: A

27. What is the difference between a class method and an instance method in Objective-C?

A. A class method is called on the class itself, whereas an instance method is called on an instance of the class
B. A class method is defined in a category, whereas an instance method is defined in the class itself
C. There is no difference between a class method and an instance method

Answer: A

28. What is a protocol in Objective-C?

A. It is a set of methods that a class must implement
B. It is a set of properties that a class must have
C. It is a set of constants that a class must use

Answer: A

29. How would you declare that a class conforms to a protocol in Objective-C?

A. @interface MyClass : NSObjectProtocol> {}
B. class MyClass : MyProtocol {}
C. public interface MyClass implements MyProtocol {}

Answer: A

30. What is the difference between a delegate and a data source in Objective-C?

A. A delegate is used to handle events, whereas a data source is used to provide data
B. A delegate is used to provide data, whereas a data source is used to handle events
C. There is no difference between a delegate and a data source

Answer: A

31. What is the syntax for creating a delegate in Objective-C?

A. @protocol MyDelegate {}
B. interface MyDelegate {}
C. public class MyDelegate {}

Answer: A

32. What is a notification in Objective-C?

A. It is a message sent to multiple objects when an event occurs
B. It is a message sent to a single object when an event occurs
C. It is a message sent whenever a property is updated

Answer: A

33. How would you register for a notification in Objective-C?

A. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(methodName:) name:@”NotificationName” object:nil];
B. [self addObserver:self forKeyPath:@”propertyName” options:NSKeyValueObservingOptionNew context:nil];
C. There is no way to register for a notification in Objective-C

Answer: A

34. How would you post a notification in Objective-C?

A. [[NSNotificationCenter defaultCenter] postNotificationName:@”NotificationName” object:nil];
B. [self postNotification:@”NotificationName” object:nil];
C. There is no way to post a notification in Objective-C

Answer: A

35. What is a target-action in Objective-C?

A. It is a way to handle events using a method on an object
B. It is a way to define a delegate
C. It is a way to define a data source

Answer: A

36. How would you define a target-action in Objective-C?

A. [button addTarget:self action:@selector(methodName:) forControlEvents:UIControlEventTouchUpInside];
B. [self addEventHandler:self forEvent:@”eventName”];
C. There is no way to define a target-action in Objective-C

Answer: A

37. What is a singleton in Objective-C?

A. It is a class that can only be instantiated once
B. It is a class that can be used to define shared resources
C. It is a class that can be used to define static data

Answer: A

38. How would you create a singleton in Objective-C?

A. +(instancetype)sharedInstance;
B. void createInstance();
C. public static Singleton getInstance();

Answer: A

39. What is a category in Objective-C?

A. It is a way to add methods to an existing class
B. It is a way to define a new class
C. It is a way to encapsulate data

Answer: A

40. How would you create a category in Objective-C?

A. @interface NSString (MyCategory) @end
B. category String(MyCategory) {}
C. There is no way to create a category in Objective-C

Answer: A

41. What is a block in Objective-C?

A. It is a way to define a method that can be passed as an argument to another method
B. It is a way to define an instance variable
C. It is a way to define a constant

Answer: A

42. How would you define a block in Objective-C?

A. void (^blockName)(void) = ^{ // block code here };
B. blockName = [^{}];
C. public void createBlock() = { // block code here };

Answer: A

43. How would you call a block in Objective-C?

A. blockName();
B. [blockName invoke];
C. There is no way to call a block in Objective-C

Answer: A

44. What is the difference between a block and a method in Objective-C?

A. A block is a piece of code that can be passed around and executed later, whereas a method is a piece of code that is executed immediately
B. A block is defined using the ^ syntax, whereas a method is defined using the – syntax
C. There is no difference between a block and a method

Answer: A

45. What is the difference between a block and a function in Objective-C?

A. A block can access variables in the enclosing scope, whereas a function cannot
B. A block is defined using the ^ syntax, whereas a function is defined using the regular C syntax
C. There is no difference between a block and a function

Answer: A

46. What is the difference between synchronous and asynchronous execution in Objective-C?

A. Synchronous execution blocks the current thread until the task is complete, whereas asynchronous execution does not
B. Synchronous execution does not block the current thread, whereas asynchronous execution does
C. There is no difference between synchronous and asynchronous execution

Answer: A

47. What is Grand Central Dispatch (GCD) in Objective-C?

A. It is a way to manage concurrency in Objective-C
B. It is a web development framework
C. It is a database management system

Answer: A

48. What is the syntax for executing a block asynchronously using GCD in Objective-C?

A. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// block code here
});
B. [self performSelectorInBackground:@selector(methodName:) withObject:nil];
C. There is no way to execute a block asynchronously using GCD

Answer: A

49. What is the syntax for executing a block synchronously using GCD in Objective-C?

A. dispatch_sync(dispatch_get_main_queue(), ^{ // block code here});
B. [self performSelectorOnMainThread:@selector(methodName:) withObject:nil waitUntilDone:YES];
C. There is no way to execute a block synchronously using GCD

Answer: A

50. What is the advantage of using GCD over NSThread in Objective-C?

A. GCD is a higher-level abstraction that provides better performance and memory management
B. NSThread is deprecated and should not be used
C. There is no advantage of using GCD over NSThread in Objective-C

Answer: A

Ashwani Kumar
Latest posts by Ashwani Kumar (see all)
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x