Objective-C Upwork Test


We don’t guarantee that all provided answers are correct.

Objective-C allows you to define protocol, which declare the method expected to be used for a particular situation. Protocol are implemented in the classes conforming to the protocol. The methods under keyword (…) must be implemented in the classes that conform the protocol and the method under (…) keyword are special optional
to implement.


  • @required, @optonal
  • @optonal, @required
  • @strong, @optonal
  • @required, @weak

What is the best way to convert NSNumber into NSString?

  • int num = {number intValue};
    NSString *string = [NSString stringWithFormat:@” %d”, num};
  • NSString *string = [NSNumber stringValue];
  • NSString *string = [NSString stringWithFormat:@” %f”, (float) number};

How do you free an object?

  • [obj release]
  • free (obj)
  • [obj free]
  • None of the above

Objective-c provide a range of methods to work with NSNumber. Which of the following methods create and returns an NSNumber object containing a given value, treating it as an NSInteger.

  • `+ (NSNumber *) numberWithInt: (int) value`
  • `- (NSInteger)integerValue`
  • `+ (NSNumber *)numberWithInt: (NSInteger)value`
  • `+ (NSNumber *)numberWithInt:(NSInteger)value `

In Objective-C, retain counts are the way in which memory is managed. When you create an object, it has a retaincount of (…). When you send an object a retain message, its retain count in incremented by (…). When you send an object release
message it’s retained count is decremented by (…). When you send an object a auto-release message, it’s retain count is decremented by (…) at some stage in the future. If an object count is reduced to (…), it is deallocated.


  • 1, 1, 1, 1, 0
  • 0, 1, 1, 1, 0
  • 1, 1, 1, 1, 1
  • 0, 1, 1, 1, 1

Can you call C++ code from the Objective-C environment?

  • Yes, from any .nm file
  • Yes, from any .cpp file
  • No

In Objective-C, Exceptions can be handled using the standard common pattern found in most other high-level programing languages. First, you need to place any code that might result in an exception in an (…) block. Then, if an exception is a thrown, the corresponding (…) block is executed to handle the problem. The (…) block is called afterwards, regardless of whether or not an exception occurred.

  • `@ catch(), @try, @finally`
  • `@try @throw, @catch()`
  • `@finally, @catch(), @throw `
  • `@try, @catch, @finally`

Look at below code and provide the reference counter value after it executes:
Object *anObj = [[Object alloc] int];
[anObj retain];
[anObj release];
[anObj release];

  • Reference counter will be 1
  • Reference counter will be 0, anObj will be deallocated automatically
  • Reference counter will be 0, anObj will be ready for the deallocation

Which of the following is NOT characteristic a category?

  • A category is adding private method and private variables that are not specific to the class and the original implementation
  • A category can be declared for any class, even if you don’t have the original implementation source code
  • Any methods that you declare in a category will be available to all instance of the original class, as well as any subclass of the original class
  • At run-time, there no difference between a method added by a category and one that is implemented by the orignal class

Which of the following contains the INCORRECT definition of a preprocessor directive

  • `#define`: Substitues a preprocessor macro
  • `#include`: Inserts a particular header from another file
  • `#under`: Undefines a preprocessor macro
  • `#error`: Issues special commands to the compiler using a standardized method
  • `#ifdef`: Returns true if this macro is defined

The Objective-C code …
@interface MyClass : NSObject


  • Indicates MyClass is part of the Sample category
  • Indicates MyClass conforms to the Sample category
  • Indicates MyClass conforms to the Sample Protocol
  • Is not valid Objective-C syntax

Which of the following is a Singleton.

  • [NSFileManager defaultManager]
  • [NSFileManager objects]
  • [NSFileManager defaultManager}
  • (NSFileManager defaultManager* objects)

When a object’s retainCount reaches 0, which message is automatically sent to that object?

  • dealloc
  • alloc
  • automated
  • object

If a is in Integer, the expression !a?

  • Uses the logical negation operator
  • Has the value 0 if a is non-zero
  • Has the value 1, if a is zero
  • All of the above

In (…), the system uses the same reference counting system as (…), but it inserts the appropriate memory management method calls for us at compile-time.

  • MRR, ARC
  • ARC, MRR
  • ARC, Garbage Collection
  • MRR, Garbage Collection
  • None of the above



Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.