Objective C Test

1. What is a pointer?
Answers:
• An object that calls other objects
• A memory address that points to a specific object
• A variable
• A class
2. What is the difference between #import and #include ?
Answers:
• #import ensures that a file is only ever included once, and #include allows the same file to be inlcuded many times.
• #include is not valid syntax
• None, they do the same thing.
• #include ensures that a file is only ever included once and #import permits the file to be included many times.
3. How do you get the Unicode character set of a Core Text font?
Answers:
• CTFontCopyDisplayName
• CTFontCopyFamilyName
• CTFontCopyCharacterSet
4. What is the method for adding KVO to your app?
Answers:
• addObserver:forKeyPath:options:context
• addKVO:forKey:
• addListener:withContext:andObject:
5. How can you declare a method, that can be set as the action to be performed on various events?
Answers:
• -(SEL) action:(id) event;
• - (IBAction) action:(id) sender;
• -(selector) action:(id) sender;
6. What is a design pattern?
Answers:
• A template for a solution to a common problem faced by programmers.
• A methodology for approching database design.
• Coding standards used by an organization.
7. True or False? For an object to use constraints, it must have at least 3 constraint values.
Answers:
• True
• False
8. Does Objective-C have constructors and destructors?
Answers:
• It depends on the object
• Only NSStrings do
• No, you use init and dealloc on Objective-C
• Yes
9. What framework is KVO (key value observing) a part of?
Answers:
• CoreData
• Foundation
• UIKit
10. If you do not declare a return type for a method definition, what is the default return type?
Answers:
• id
• No return type
• *NSString
11. What class supports the sharing of small amounts of data such as strings or dates to iCloud?
Answers:
• NSUbiquitousKeyValueStore
• NSUrlConnection
• NSOperation
12. Assume ARC is enabled... What would be another way to write this: NSArray *array  = [NSArray arrayWithObjects:@"One", @"Two", @"Three",nil];
Answers:
• NSArray *array = {@"One", @"Two",@"Three"};
• NSArray *array = @[@"One", @"Two", @"Three"];
• NSArray *array = [@"One", @"Two",@"Three"];
• NSArray *array = @{@"One", @"Two", @"Three"};
13. What is the type of @selector(foo)?
Answers:
• SEL
• selector
• id
• None, that is not a valid Objective-C expression.
14. Using UIViewController containment, which one of the following statements is true:
Answers:
• Every viewcontroller can handle the loading and unloading of other viewcontroller.
• The root viewcontroller handles loading and unloading its child viewcontrollers.
15. what does this code produce?   [NSString] *myString = @"Hello World";
Answers:
• An Error during compile
• it put the value Hello World into a string named myString
• gets SIGABRT while executing the application
• none of the above
• makes the pointer to myString equal to the pointer of the new created object with @"hello world"
16. Can you call C++ code from objective C environment?
Answers:
• Yes, from any .m file
• No, it is not possible
• Yes, from any .mm file
17. What is a dependency in NSOperationQueue?
Answers:
• A dependency sets the variables of the NSOperationQueue
• A dependency is a way to have an operation wait to be performed until the dependencies have been fulfilled/executed
• A dependency is the alloc/init method of the NSOperationQueue
18. If a class conforms to a protocol what must it do?
Answers:
• Implement all or some methods and leave the rest to be implemented by subclasses
• Implement all methods in the protocol without exception
• Implement all methods in the protocol, except for optional ones
• Implement all methods which do not have a default implementation in the protocol
19. Which of the following accesses a variable in structure b?
Answers:
• b->var;
• b>var;
• b-var;
• b.var;
• b
20. How can you add a new method foo to an existing class Bar?
Answers:
• 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).
• Send Bar the "extend:" message, e.g. [Bar extend: foo].
• It's not possible.
• Both "extend" options are correct.
21. 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.
Answers:
• True
• False
22. What is KVO?
Answers:
• Key Variable Obfuscation
• Key Value Operations
• Key Value Observing
23. What is  a Category?
Answers:
• 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 is a way to extend a class by adding functions to it
• One way to alter the destination of a message at runtime by switching the implementations.
• A category defines a set of functions which a class implements
24. True or False? A method and a variable can have the same name in Objective-C.
Answers:
• True
• False
25. How does KVO respond to change notifications?
Answers:
• respondToValueChange:forKey:
• observeValueForKeyPath:ofObject:change:context
• listenToChange:forObject:andContext:
26. What is the Allocations instrument used for?
Answers:
• Recording information from a single process about memory allocation
• Allows you to view your variable values
• A debugging tool that frees up memory
27. What is used to sort Core Data results?
Answers:
• NSCoreDataSort
• NSSort
• NSSortDescriptor
• [self sort]
28. True or False? You can compare two strings by (string1 == string2)
Answers:
• True
• False
29. What is the difference between methods that begin with + and -?
Answers:
• + methods are inheritable, - methods are not
• + methods are public, - methods are private
• Instance methods begin with - class level methods begin with +
30. What does a CAEmitterCell do?
Answers:
• Nothing, it is not a valid class
• It intercepts touch events
• It defines the properties and direction of emitted particles from a CAEmitterLayer object.
• It is used by the GPS to track user coordinates and returns to values as coordinates
31. What happens when you call retain on an object?
Answers:
• You increase its retain count by 1
• It is permanently stored in memory
• It is released from memory
• It will stay in memory until the app closes
32. What type of object is this under XCode 4.5: @[rabbit, chicken, owl]
Answers:
• NSString
• NSDictionary
• NSArray
• SQLite schema
33. How do you free an object?
Answers:
• [obj release]
• None of the above
• free(obj)
• [obj free]
• [obj dealloc]
34. True or False? A UIButton inherits from UIView.
Answers:
• False
• True
35. What does the "id" type mean?
Answers:
• This is a type for strings
• This is the general type for any kind of object regardless of class
• This is a type for a specific object of class id
36. Which of the following is a Singleton?
Answers:
• [NSFileManager defaultManager]
• [NSArray array]
37. How do you concatenate two NSStrings *foo and NSString *bar to form a new NSString *baz?
Answers:
• baz = foo & bar;
• baz = [foo appendString: bar];
• baz = [foo stringByAppendingString: bar];
• baz = [foo concat: bar];
• baz = foo + bar;
38. What framework does the class UIButton come from?
Answers:
• UIKit
• CoreGraphics
• EventKit
• OpenGLES
• Foundation
39. Are integers full-fledged objects in Objective-C?
Answers:
• Integers are only partial objects in Objective-C (e.g. do not support any user defined methods).
• Yes, but only if you first cast them as id's, e.g. (id) 123.
• No, they are not objects at all.
• Yes.
40. What does an Objective-C string literal look like?
Answers:
• @"foo"
• #"foo"
• $"foo"
• "foo"
• NSString("foo")
41. If you define a new class called Foo which inherits from NSObject, how do you create a new instance of it?
Answers:
• Foo *temp = Make Instance of Foo;
• Foo *temp = new Foo();
• Foo *temp = System.Create(Foo);
• Foo *temp = [Foo init];
• Foo *temp = [[Foo alloc] init];
42. ARC means?
Answers:
• Artificial Reference Counting
• Application Reference Collection
• Angular Reference Courting
• Access Reference Collation
• Automatic Reference Counting
43. Where is a MKAnnotationView used?
Answers:
• On a cell
• In a button
• On a table view
• On a Map View
44. What is a delegate?
Answers:
• Time's Up!
• A delegate is a UIView
• A delegate is a variable
• A delegate allows one NSObject to send messages to another NSObject, and listen to those messages
• A delegate holds the type of data a variable stores
45. What is the name of the type of SQL Database that iOS Supports?
Answers:
• MySql
• SQL
• SQLite
• NoSql
46. What is one source of particles that are emitted by a CAEmitterLayer object?
Answers:
• A CAEmitterCell
• A UIEmitterView
• A NSEmitter
47. In Core Data, what is the name of an object representation of a record?
Answers:
• NSManageObjectContext
• NSEntityDescription
• NSManagedObjectModel
• NSManagedObject
48. True or False? You should use NSHost when connecting to a specific host.
Answers:
• False (You should use CFHost)
• True
49. What happens at runtime with the following:  NSObject* object = nil; NSObject* object2 = [object copy]; NSLog(@"%@", object2);
Answers:
• object2 is instantiated as an NSObject with nil values
• Application crashes with "SIGABRT: object has been derferenced" error
• Application continues, but issues "cannot access nil object reference" warning
• Log prints "(null)" and continues as usual.
50. True or False? You can perform operator overloading in Objective-C.
Answers:
• True
• False
51. True or False? Strings are one of the most common sources of buffer overflow attacks.
Answers:
• True
• False
52. What class will allow you to use one or more blocks concurrently?
Answers:
• NSBlock
• NSConcurrency
• NSBlockOperation
• NSConcurrentBlock
53. What is the 'print object' command in the debugger window?
Answers:
• po
• -l
• p
• print
54. The proper typedef syntax for an Objective-C block that takes an NSArray and returns an NSString is
Answers:
• typedef NSString *(^aBlock)(NSArray *);
• typedef void(^aBlock)(void);
• typedef NSArray *(^aBlock)(NSString *);
• typedef aBlock^ = (NSString *)(NSArray *);
55. What is a persistent object store?
Answers:
• It is the schema for your object
• It is the relationships between tables in your data
• It represents an external file of persisted data
• It is retained database objects
56. What is the difference between [Foo new] and [[Foo alloc] init]?
Answers:
• New will not always initialize the object.
• New does not exist in Objective-C.
• None, they perform the same actions.
• New is significantly faster than alloc + init.
57. What is a proper format for calling an asynchronous function?
Answers:
• [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 ];
• [dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ // code })];
58. What are the two types of predicates?
Answers:
• Expression and Operator
• Filter and Exclusion
• Comparison and Compound
59. What is Objective-C's language design based on?
Answers:
• C and BCPL.
• C and C++.
• C and Objectivity.
• C and Smalltalk.
• C and Cocoa.
60. True or False? You can use %@ to specify a dynamic property.
Answers:
• True
• False
61. How do you convert a Core Image color to a UIColor?
Answers:
• UIColorValue:
• UIColorWithCIColor:
• colorWithCIColor:
• CIColorValue:
62. In Core Data, what is the name of the object representation for the database schema?
Answers:
• NSManageObjectContext
• NSManagedObjectModel
• NSEntityDescription
• NSManagedObject
63. What can happen if you use self inside a block?
Answers:
• You can create a retain cycle
• None of the above
• self can become a dangling pointer
• By the time the block executes, self can be pointing to a different object
64. 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:
Answers:
• instancetype
• returntype
• resultType
• NSRelatedType
• id
65. True or False? The format for a NSPredicate is the same as a Regular Expression.
Answers:
• True
• False
66. What protocol is used to create an action object?
Answers:
• None of These
• CoreAnimation
• NSAction
• CAAction
67. What is the object.toString equivalent in objective-c?
Answers:
• [NSObject getDetails]
• [NSObject description]
• [NSObject toString]
• [NSObject stringWithFormat]
• [NSObject getDescription]
68. How can you temporarily disable layer actions in a Core Animation?
Answers:
• Using the CATransaction class
• Using the CAExit class
• Using the CAStopAnimation class
• Using the CAStop class
69. What class method is used to make an NSArray from NSData class?
Answers:
• NSFileManager defaultManager
• NSArray arrayWithObject:
• NSKeyedUnarchiver unarchiveObjectWithData:
• NSData dataWithContentsOfFile:
70. What is (void*)0 ?
Answers:
• Error
• Representation of void pointer
• Representation of NULL pointer
• None of above
71. Which of these property declaration attributes does not specify setter semantics?
Answers:
• copy
• strong
• weak
• nonatomic
• assign
72. Which of these classes is NOT a root class?
Answers:
• NSString
• NSZombie
• NSProxy
• NSMessageBuilder
• NSObject
73. What does the following code do, assume ARC is enabled?      NSArray *myArray;     for (int i = 0; i < 10; i++){         @autoreleasepool {             myArray = [[NSArray alloc]init];         }     }
Answers:
• For each iteration of the loop a new array is allocated and will leak memory.
• 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.
74. True or False? Key value coding is used to indirectly access an object's attributes using indexes.
Answers:
• True
• False
75. If you wanted to override the default alloc method in a class Foo, what would be the appropriate way to declare it?
Answers:
• - (Foo *) alloc;
• - (id) alloc;
• It's not possible to override alloc.
• + (Foo *) alloc;
• + (id) alloc;
76. What do you use for an outgoing TCP connection?
Answers:
• NSStream
• NSTCPProtocol
• (none of these)
• NSUrlStream
77. What happens if you use fgets and do not give it a size smaller than the buffer?
Answers:
• It will clip its size automatically
• It will use the size of the object as its size
• None of these
• It will overwrite the data past the size
78. What can you say about the code:  NSString * str = [NSString stringWithFormat:@""]; [str release];
Answers:
• It will cause the string to be released twice with undefined consequences when the surrounding autorelease pool is emptied
• None of these
• it will cause a SIGABRT when the enclosing method ends
• It is correct, everything will work fine
• It will cause a SIGSEGV at [str release];
79. How do you add a brightening effect on a CoreImage?
Answers:
• CIBrighten
• Set the alpha
• CIAdditionCompositing
80. Which method, if defined, is guaranteed to be called once -- and only once -- when a class is first referenced?
Answers:
• + (id) init;
• + (Class) alloc;
• + (void) initialize;
• + (id) alloc;
• + (void) init;
81. Which of these methods is NOT invoked by the runtime itself?
Answers:
• -dealloc
• -forwardInvocation:
• +load
• -doesNotRecognizeSelector:
• +initialize
82. What is the last chance for an object to handle a message?
Answers:
• -respondsToSelector:
• +instancesRespondToSelector:
• +resolveInstanceMethod:
• -forwardInvocation:
• -forwardingTargetForSelector:
83. How is a selector typically represented in memory?
Answers:
• As a null terminated C string.
• As a unique 32-bit number.
• As an Objective-C object.
• As a pointer to a C struct.

No comments:

Post a Comment