NSMutableString *s = [NSMutableString stringWithString: @"123"];
1.
123456
2.
123
3.
456
4.
This code contains an error.
Q 1 / 40
NSString *str = nil; NSInteger i = str.integerValue;
1.
nil
2.
0 (technically `nil` == 0 but i will have a literal value of `0` and not the `void*` value of `nil`)
3.
-1
4.
This code crashes.
Q 2 / 40
`NSString str = "test" + " " + "more";`
1.
This code contains an error
2.
test
3.
nil
4.
test more
Q 3 / 40
NSPredicate *p2 = [NSPredicate predicateWithBlock:^BOOL(NSString* evaluatedObject, NSDictionary<NSString *,id> * _Nullable bindings) { return evaluatedObject.intValue % 2 == 0; }]; NSArray *vals = @[@"1", @"2", @"3"]; NSArray *n2 = [vals filteredArrayUsingPredicate:p2]; NSLog(@"%@", n2.firstObject);
1.
2
2.
1,2,3
3.
1,2
4.
Nothing, since this code contains an error.
Q 4 / 40
1.
atomic/strong
2.
atomic/weak
3.
nonatomic/weak
4.
nonatomic/strong
Q 5 / 40
1.
NSMutableDictionary's values can change
2.
NSMutableDictionary has not initializers.
3.
NSDictionary can't be copied.
4.
NSDictionary's values can change.
Q 6 / 40
`-(float)foo;`
1.
A function with a return type of float.
2.
This code contains an error.
3.
A variable declaration of type float.
4.
A property of type float.
Q 7 / 40
`#import "NSString+NameHelper.h"`
1.
NameHelper is a category of NSString.
2.
NameHelper is a subclass of NSString.
3.
NSString implements the NameHelper protocol.
4.
NSString has a helper class.
Q 8 / 40
`float x = 5.;`
1.
Nothing is wrong with this code.
2.
Declarations do not need semicolons.
3.
x=5 is an invalid float.
4.
Variables can't be declared and initialized in the same state.
Q 9 / 40
for (int x=0; x<100; x++) { x = x + 1; }
1.
50
2.
99
3.
100
4.
This code contains an error.
Q 10 / 40
`[self addObserver: self forKeyPath: @"val" options:0 context: nil];`
1.
Key-Value Observing
2.
Class Value Observing
3.
Key-Data Observing
4.
KeyPath Observing
Q 11 / 40
1.
Automatic Reference Counting
2.
Automatic Retain Checking
3.
Async Retain Cycles
4.
Automatic Release Code
Q 12 / 40
int val = 0; val = 1.5; printf("%d", val);
1.
1
2.
2
3.
0
4.
This code contains an error.
Q 13 / 40
1.
single inheritance but multiple protocol implementation
2.
Objective-C doesn't support inheritance
3.
dual class inheritance
4.
unlimited class inheritance and protocol adherence
Q 14 / 40
`NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys: @"b", @"e", @"a", @"r", nil];`
1.
2
2.
4
3.
5
4.
This code contains an error.
Q 15 / 40
NSMutableDictionary *dict1 = [NSMutableDictionary dictionaryWithCapacity:5];
1.
The key and value items are mixed
2.
Nothing is wrong with it
3.
You can't set the capacity of a dictionary
4.
NSMutableDictionary doesn't have a :setValue:forKey function.
Q 16 / 40
NSData *data = [@"print" dataUsingEncoding:NSASCIIStringEncoding]; NSLog(@"%@", [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]);
1.
2.
This code is invalid
3.
Nothing is printed from this code.
4.
nil
Q 17 / 40
`+(void)doSomething;`
1.
It is static
2.
It is abstract.
3.
It is inline.
4.
This code contains an error.
Q 18 / 40
1.
functions
2.
initializers
3.
fields
4.
all of these answers
Q 19 / 40
@interface MyClass : NSObject @property (strong, nonatomic, readonly) NSString *name; @end
1.
There is nothing wrong with this code.
2.
There is not read-only directive.
3.
MyClass doesn't implement NSObject.
4.
Properties are declared in the implementation.
Q 20 / 40
`typedef enum { Foo1, Foo2} Foo;`
1.
There is no base type.
2.
NSObject
3.
int
4.
NSNumber
Q 21 / 40
1.
UserDefaults
2.
plist file
3.
CoreData
4.
TextFile
Q 22 / 40
1.
to extend other classes
2.
to manage access control
3.
to coordinate objects
4.
to group classes
Q 23 / 40
if ([keyPath isInstanceOf:[NSString class]]) { }
1.
This code contains an error
2.
if keyPath is an instance of NSString
3.
if keyPath's baseclass is the same as NSString's baseclass
4.
if keyPath implements the same methods as NSString
Q 24 / 40
`int(^foo)(int);`
1.
an Extension
2.
a Generic
3.
a block of code
4.
an abstract class
Q 25 / 40
1. _val = 1; 2. self.val= 100;
1.
Statement 2, since it calls the auto-created setter on the property.
2.
Statement 1, since it uses the property directly.
3.
Statement 2, since it specifies the class instance to use.
4.
Statement 1, since it calls the auto-created setter on the property.
Q 26 / 40
float x = 2.0; int(^foo)(int) = ^(int n1) { return (int)(n1*x); }; foo(5);
1.
Ints and floats can't be multiplied.
2.
The parameter isn't declared correctly.
3.
x is not in the right scope.
4.
Nothing is wrong with this code.
Q 27 / 40
1.
Arrays are ordered, non-unique values.
2.
Arrays are stored sorted.
3.
Sets are ordered, unique values.
4.
Sets can contain nils.
Q 28 / 40
1.
nothing, as they're never used in Objective-C
2.
function calls only
3.
property getter/setter
4.
parameter delimiters
Q 29 / 40
NSArray *vals = @[@"1", @"2", @"3"]; NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF.intValue > 1"]; NSArray *newVals = [vals filteredArrayUsingPredicate:pred];
1.
2,3
2.
nil
3.
This code contains an error
4.
2,"3"
Q 30 / 40
`-(int)foo:(int)a b:(int)c;`
1.
self.foo(5, b:10);
2.
This code contains an error.
3.
[self foo:5:10:20];
4.
[self foo:5 b:10];
Q 31 / 40
NSError *error; NSData *data; id json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
1.
NSString
2.
NSArray
3.
id
4.
NSDictionary
Q 32 / 40
-(void)testFunc:(NSString**)str;
1.
The parameter is passed by value and can not be changed
2.
** is not allowed on a parameter
3.
The parameter may be nil
4.
The parameter is passed by reference and may be changed
Q 33 / 40
typedef enum { thing1, thing2, thing3 } Thing; -(void) enumStuff { NSLog(@"%d", thing2); }
1.
0
2.
1
3.
thing2
4.
This code does not print anything
Q 34 / 40
1.
non-atomic
2.
strong
3.
weak
4.
atomic
Q 35 / 40
int temp = 1==1;
1.
`temp` is a keyword.
2.
1==1 is invalid.
3.
1==1 evaluates to a Boolean.
4.
Nothing is wrong with it.
Q 36 / 40
dispatch_async(dispatch_get_main_queue(), ^{ // code });
1.
It executes on the main queue.
2.
It is the last code to run before the app goes inactive.
3.
It executes on a background thread.
4.
It is queued to execute in the background.
Q 37 / 40
NSMutableSet *set1 = [NSMutableSet setWithObjects: @1,@2, @3, @4, @5, nil];
1.
zero
2.
six
3.
one
4.
five
Q 38 / 40
NSDictionary *d1 = @[@"v1", @4, @"v2", @5.6, @"v3"]; NSlog(@"d1: %@", d1);
1.
NSDictionary cannot be printed this way.
2.
The last key is missing a value.
3.
Dictionaries cannot have mixed types as values.
4.
d1 is assigned an NSArray of values.
Q 39 / 40
@property (nonatomic, readonly) int val;
1.
8
2.
nil
3.
-1
4.
undefined
Q 40 / 40