Elance Objective C Test Answers 2015


What is a pointer?
A variable
A memory address that points to a specific object
An object that calls other objects
A class


If you do not declare a return type for a method definition, what is the default return type?
*NSString
id
No return type


What is the Allocations instrument used for?
Allows you to view your variable values
A debugging tool that frees up memory
Recording information from a single process about memory allocation


what does this code produce? [NSString] *myString = @"Hello World";
An Error during compile
makes the pointer to myString equal to the pointer of the new created object with @"hello world"
gets SIGABRT while executing the application
it put the value Hello World into a string named myString
none of the above


How do you get the Unicode character set of a Core Text font?
CTFontCopyDisplayName
CTFontCopyCharacterSet
CTFontCopyFamilyName


True or False? A UIButton inherits from UIView.
True
False


Developers are allowed to call [super dealloc] in ARC.
TRUE
FALSE


What is the difference between methods that begin with + and -?
Instance methods begin with - class level methods begin with +
+ methods are inheritable, - methods are not
+ methods are public, - methods are private


How can you declare a method, that can be set as the action to be performed on various events?
- (IBAction) action:(id) sender;
-(SEL) action:(id) event;
-(selector) action:(id) sender;


What is KVO?
Key Variable Obfuscation
Key Value Operations
Key Value Observing


What is a Category?
A category is a way to extend a class by adding functions to it
A category is adding methods to a class where pointers in the memory no longer exist for an instance of a class to execute it.
A category defines a set of functions which a class implements
One way to alter the destination of a message at runtime by switching the implementations.


True or False? You can compare two strings by (string1 == string2)
True
False


To have an IOS app Screen Design we used which of the following tool?
None of above
Interface Xcode
Interface builder
Interface Designer
Instruments


What does the "id" type mean?
This is the general type for any kind of object regardless of class
This is a type for a specific object of class id
This is a type for strings


What is the method for adding KVO to your app?
addKVO:forKey:
addListener:withContext:andObject:
addObserver:forKeyPath:options:context


How do you concatenate two NSStrings *foo and NSString *bar to form a new NSString *baz?
baz = foo + bar;
baz = [foo stringByAppendingString: bar];
baz = foo & bar;
baz = [foo appendString: bar];
baz = [foo concat: bar];


What framework does the class UIButton come from?
CoreGraphics
Foundation
EventKit
UIKit
OpenGLES


If you define a new class called Foo which inherits from NSObject, how do you create a new instance of it?
Foo *temp = new Foo();
Foo *temp = Make Instance of Foo;
Foo *temp = [[Foo alloc] init];
Foo *temp = System.Create(Foo);
Foo *temp = [Foo init];


What does an Objective-C string literal look like?
"foo"
#"foo"
@"foo"
$"foo"
NSString("foo")


ARC means?
Automatic Reference Counting
Angular Reference Courting
Access Reference Collation
Artificial Reference Counting
Application Reference Collection


Where is a MKAnnotationView used?
On a cell
In a button
On a Map View
On a table view


What is a delegate?
A delegate is a UIView
A delegate holds the type of data a variable stores
A delegate allows one NSObject to send messages to another NSObject, and listen to those messages
A delegate is a variable


Which of the following is a Singleton?
[NSArray array]
[NSFileManager defaultManager]


Which of the following is an object?
double
NSNumber
int
float


What is the name of the type of SQL Database that iOS Supports?
SQL
NoSql
SQLite
MySql


What type of object is this under XCode 4.5: @[rabbit, chicken, owl]
SQLite schema
NSArray
NSString
NSDictionary


What does a CAEmitterCell do?
Nothing, it is not a valid class
It defines the properties and direction of emitted particles from a CAEmitterLayer object.
It intercepts touch events
It is used by the GPS to track user coordinates and returns to values as coordinates


What happens when you call retain on an object?
It is permanently stored in memory
It will stay in memory until the app closes
You increase its retain count by 1
It is released from memory


How do you free an object?
[obj release]
None of the above
free(obj)
[obj dealloc]
[obj free]


How does KVO respond to change notifications?
respondToValueChange:forKey:
listenToChange:forObject:andContext:
observeValueForKeyPath:ofObject:change:context


What is a dependency in NSOperationQueue?
A dependency is a way to have an operation wait to be performed until the dependencies have been fulfilled/executed
A dependency sets the variables of the NSOperationQueue
A dependency is the alloc/init method of the NSOperationQueue


True or False? Sending a command asynchronously will lock the main thread and then wait until the command is finished before moving on to the next part of your code.
False
True


Which of the following accesses a variable in structure b?
b.var;
b-var;
b>var;
b->var;
b


If a class conforms to a protocol what must it do?
Implement all methods in the protocol, except for optional ones
Implement all methods in the protocol without exception
Implement all or some methods and leave the rest to be implemented by subclasses
Implement all methods which do not have a default implementation in the protocol


True or False? For an object to use constraints, it must have at least 3 constraint values.
False
True


What is used to sort Core Data results?
NSSort
NSCoreDataSort
[self sort]
NSSortDescriptor


True or False? A method and a variable can have the same name in Objective-C.
False
True


What is a design pattern?
A methodology for approching database design.
Coding standards used by an organization.
A template for a solution to a common problem faced by programmers.


How can you add a new method foo to an existing class Bar?
Both "extend" options are correct.
It's not possible.
Send Bar the "extend:" message, e.g. [Bar extend: foo].
Define a C function foo and then send Bar the extend:withSelector: message, e.g. [Bar extend: foo withSelector: @selector(foo:)].
Make a category, e.g. @interface Bar(Foo).


Can you call C++ code from objective C environment?
Yes, from any .mm file
Yes, from any .m file
No, it is not possible


What framework is KVO (key value observing) a part of?
Foundation
UIKit
CoreData


Assume ARC is enabled... What would be another way to write this: NSArray *array = [NSArray arrayWithObjects:@"One", @"Two", @"Three",nil];
NSArray *array = [@"One", @"Two",@"Three"];
NSArray *array = @[@"One", @"Two", @"Three"];
NSArray *array = {@"One", @"Two",@"Three"};
NSArray *array = @{@"One", @"Two", @"Three"};


let a:int=5 a=10 this code is true of false?
false
true


Does Objective-C have constructors and destructors?
Yes
It depends on the object
No, you use init and dealloc on Objective-C
Only NSStrings do


What is the type of @selector(foo)?
id
selector
None, that is not a valid Objective-C expression.
SEL


What class supports the sharing of small amounts of data such as strings or dates to iCloud?
NSUrlConnection
NSOperation
NSUbiquitousKeyValueStore


Are integers full-fledged objects in Objective-C?
Yes, but only if you first cast them as id's, e.g. (id) 123.
No, they are not objects at all.
Integers are only partial objects in Objective-C (e.g. do not support any user defined methods).
Yes.


Using UIViewController containment, which one of the following statements is true:
The root viewcontroller handles loading and unloading its child viewcontrollers.
Every viewcontroller can handle the loading and unloading of other viewcontroller.


What is the difference between [Foo new] and [[Foo alloc] init]?
New will not always initialize the object.
New is significantly faster than alloc + init.
None, they perform the same actions.
New does not exist in Objective-C.


What is one source of particles that are emitted by a CAEmitterLayer object?
A UIEmitterView
A NSEmitter
A CAEmitterCell


What is the 'print object' command in the debugger window?
print
p
-l
po


What happens at runtime with the following: NSObject* object = nil; NSObject* object2 = [object copy]; NSLog(@"%@", object2);
Application crashes with "SIGABRT: object has been derferenced" error
Application continues, but issues "cannot access nil object reference" warning
object2 is instantiated as an NSObject with nil values
Log prints "(null)" and continues as usual.


What is @dynamic directive meaning in iOS?
The @dynamic directive generates the accessor methods for you at compile time.
The @dynamic directive tells the compiler that you will provide accessor methods dynamically at runtime.
The @dynamic directive generates getter method for your property at compile time.
The @dynamic directive generates setter method for your property at compile time.


What class will allow you to use one or more blocks concurrently?
NSBlockOperation
NSConcurrentBlock
NSConcurrency
NSBlock


In Core Data, what is the name of an object representation of a record?
NSManagedObjectModel
NSManageObjectContext
NSManagedObject
NSEntityDescription


What is Objective-C's language design based on?
C and C++.
C and Cocoa.
C and Smalltalk.
C and BCPL.
C and Objectivity.


True or False? You should use NSHost when connecting to a specific host.
True
False (You should use CFHost)


What is the difference between #import and #include ?
#import ensures that a file is only ever included once, and #include allows the same file to be inlcuded many times.
None, they do the same thing.
#include is not valid syntax
#include ensures that a file is only ever included once and #import permits the file to be included many times.


True or False? Strings are one of the most common sources of buffer overflow attacks.
True
False


True or False? You can use %@ to specify a dynamic property.
True
False


What is a proper format for calling an asynchronous function?
[dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), // code ];
[NSOperationDispatchAsync dispatch_asyncWithBlock: ^{ // code }];
[dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ // code })];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ // code });


True or False? You can perform operator overloading in Objective-C.
False
True


What are the two types of predicates?
Expression and Operator
Comparison and Compound
Filter and Exclusion


What is a persistent object store?
It represents an external file of persisted data
It is the relationships between tables in your data
It is the schema for your object
It is retained database objects


The proper typedef syntax for an Objective-C block that takes an NSArray and returns an NSString is
typedef aBlock^ = (NSString *)(NSArray *);
typedef NSArray *(^aBlock)(NSString *);
typedef void(^aBlock)(void);
typedef NSString *(^aBlock)(NSArray *);


How do you convert a Core Image color to a UIColor?
UIColorWithCIColor:
UIColorValue:
CIColorValue:
colorWithCIColor:


How can you temporarily disable layer actions in a Core Animation?
Using the CATransaction class
Using the CAStopAnimation class
Using the CAExit class
Using the CAStop class


What can happen if you use self inside a block?
None of the above
self can become a dangling pointer
You can create a retain cycle
By the time the block executes, self can be pointing to a different object


True or False? The format for a NSPredicate is the same as a Regular Expression.
False
True


Objective-C methods with certain names (“init”, “alloc”, etc.) always return objects that are an instance of the receiving class’s type; such methods are said to have a “related result type”. A method with a related result type can be declared by using:
returntype
id
resultType
instancetype
NSRelatedType


In Core Data, what is the name of the object representation for the database schema?
NSManageObjectContext
NSManagedObjectModel
NSEntityDescription
NSManagedObject


Which framework lets you determine the current location or heading associated with a device?
CFLocation
MapKit
LocationKit
CoreLocation
NSLocation


What is (void*)0 ?
Representation of void pointer
None of above
Representation of NULL pointer
Error


What protocol is used to create an action object?
CoreAnimation
CAAction
NSAction
None of These


Which of these classes is NOT a root class?
NSString
NSMessageBuilder
NSObject
NSProxy
NSZombie


True or False? Key value coding is used to indirectly access an object's attributes using indexes.
True
False


What is the object.toString equivalent in objective-c?
[NSObject toString]
[NSObject description]
[NSObject stringWithFormat]
[NSObject getDescription]
[NSObject getDetails]


What does the following code do, assume ARC is enabled? NSArray *myArray; for (int i = 0; i < 10; i++){ @autoreleasepool { myArray = [[NSArray alloc]init]; } }
For each iteration of the loop a new array is allocated and released.
For each iteration of the loop a new array is allocated and will be released at the end of the loop.
For each iteration of the loop a new array is allocated only.
For each iteration of the loop a new array is allocated and will leak memory.


What happens if you use fgets and do not give it a size smaller than the buffer?
It will use the size of the object as its size
It will overwrite the data past the size
It will clip its size automatically
None of these


how can we return multiple values from function?
not possible
void*
tuple


If you wanted to override the default alloc method in a class Foo, what would be the appropriate way to declare it?
- (Foo *) alloc;
+ (Foo *) alloc;
+ (id) alloc;
It's not possible to override alloc.
- (id) alloc;


What is not supported in Objective-C
Recursive method call
Method argument default value
Variable argument count to method
Byte manipulation


What class method is used to make an NSArray from NSData class?
NSArray arrayWithObject:
NSFileManager defaultManager
NSData dataWithContentsOfFile:
NSKeyedUnarchiver unarchiveObjectWithData:


What do you use for an outgoing TCP connection?
NSStream
NSTCPProtocol
(none of these)
NSUrlStream


Which method, if defined, is guaranteed to be called once -- and only once -- when a class is first referenced?
+ (id) alloc;
+ (void) init;
+ (id) init;
+ (Class) alloc;
+ (void) initialize;


Which of these property declaration attributes does not specify setter semantics?
strong
assign
nonatomic
weak
copy


What can you say about the code: NSString * str = [NSString stringWithFormat:@""]; [str release];
it will cause a SIGABRT when the enclosing method ends
It will cause the string to be released twice with undefined consequences when the surrounding autorelease pool is emptied
It will cause a SIGSEGV at [str release];
None of these
It is correct, everything will work fine


How do you add a brightening effect on a CoreImage?
Set the alpha
CIBrighten
CIAdditionCompositing


Which of these methods is NOT invoked by the runtime itself?
-forwardInvocation:
+load
+initialize
-dealloc
-doesNotRecognizeSelector:


What is the last chance for an object to handle a message?
-forwardInvocation:
-forwardingTargetForSelector:
-respondsToSelector:
+resolveInstanceMethod:
+instancesRespondToSelector:


A UITableViewController's tableview must have its delegate explicitly set by the developer.
TRUE
FALSE


What's the difference between nil and NULL?
nil is literal null value for Objective-C instances. NULL is object used to represent null
nil is literal null value for Objective-C instances. NULL is literal null value for Objective-C classes
nil is literal null value for Objective-C instances. NULL is literal null value for C pointers
NULL is literal null value for Objective-C instances. nil is literal null value for C pointers
they are the same thing


How is a selector typically represented in memory?
As a pointer to a C struct.
As a unique 32-bit number.
As a null terminated C string.
As an Objective-C object.


A UIView is a superclass of:
UIViewController
UIWindow
UIImage
UILabel
UIScreen


What are @try and @catch?
Exception keywords
All of these
Exception handlers
Exceptions


How to restore Consumable In-App Purchases?
Use Store Kit’s finishTransaction: method
Consumable In-App Purchases are not to be restored
Use Store Kit’s addPayment: method
Use Store Kit’s initWithProductIdentifiers: method
Use Store Kit’s restoreCompletedTransactions method


What happens at runtime with the following: NSMutableString *tempString = [NSMutableString stringWithString:@"1"]; dispatch_sync(dispatch_get_main_queue(), ^{ [tempString appendString:@"2"]; NSLog(@"%@", tempString); }); [tempString appendString:@"3"];
Log prints "132" and continues as usual.
Log prints "12" and then we will have a deadlock here because the main queue will block
Log prints "123" and continues as usual.
Log doesn't print anything. It's a deadlock here because the main queue will block on the call to dispatch_sync


What сan you use to avoid msgSend function overhead?
None of these
IMP
SEL
You can't use anything


Which of the following statements is correct?
@property(readwrite,retain,atomic)NSInteger value;
@property(readwrite,copy,atomic)NSInteger value;
@property(readwrite,retain,atomic,copy)NSInteger value;
@property(readwrite,assign,copy,atomic)NSInteger value;
none of the above


What happens at runtime with the following: dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_apply(10, queue, ^(size_t index) { NSLog(@"%zu", index); });
Log prints "0123456789"
We won't have persistent result
Log prints "12345678910"
Log prints "9876543210"