Q1. What is the value of s?
NSMutableString *s = [NSMutableString stringWithString: @"123"];
[s appendString: @"456"];
Q2. What's the value of i after these statements?
NSString *str = nil;
NSInteger i = str.integerValue;
Q3. What value is in str after this line in executed?
NSString str = "test" + " " + "more";
Q4. What is the output of the code given below?
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);
Q5. Property defaults include _?
Q6. What is the key difference between NSDictionary and NSMutableDictionary?
Q7. What is foo?
-(float)foo;
Q8. What can you glean from this line?
#import "NSString+NameHelper.h"
Q9. What's wrong with this code?
float x = 5.;
Q10. How many times with this loop be executed?
for (int x=0; x<100; x++) {
x = x + 1;
}
Q11. What is this code an example of?
[self addObserver: self forKeyPath: @"val" options:0 context: nil];
Q12. What does ARC stand for?
Q13. What is printed for this code?
int val = 0;
val = 1.5;
printf("%d", val);
Q14. What best describes class inheritance in Objective-C?
Q15. How many keys does this NSDictionary have after this code is executed?
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys: @"b", @"e", @"a", @"r", nil];
Q16. What is the error in this code?
NSMutableDictionary *dict1 = [NSMutableDictionary dictionaryWithCapacity:5];
[dict1 setValue:@"key" forKey:@"value"];
Q17. What is printed from this code?
NSData *data = [@"print" dataUsingEncoding:NSASCIIStringEncoding];
NSLog(@"%@", [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]);
Q18. What is different about this function?
+(void)doSomething;
Q19. Structs can have _?
Q20. What is wrong with this code?
@interface MyClass : NSObject
@property (strong, nonatomic, readonly) NSString *name;
@end
Q21. What is an enums base type for the code below?
typedef enum { Foo1, Foo2} Foo;
Q22. If you want to store a small amount of information (e.g., user settings), whats the best, built-in way to go?
Q23. What are categories used for?
Q24. What is this Objective-C code checking?
if ([keyPath isInstanceOf:[NSString class]]) {
}
Q25. What is this a declaration of?
int(^foo)(int);
Q26. For observing changes to a property, which of these two statements cause the related method to be called and why?
1. _val = 1;
2. self.val= 100;
Q27. What is wrong with this code?
float x = 2.0;
int(^foo)(int) = ^(int n1) {
return (int)(n1*x);
};
foo(5);
Q28. What's the difference between an array and a set?
Q29. Dot notation can be used for _?
Q30. What is the value of newVals after this code is executed?
NSArray *vals = @[@"1", @"2", @"3"];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF.intValue > 1"];
NSArray *newVals = [vals filteredArrayUsingPredicate:pred];
Q31. How would this function be called?
-(int)foo:(int)a b:(int)c;
Q32. What is the type of the error return value stored in json?
NSError *error;
NSData *data;
id json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
Q33. What is significant about this function declaration?
-(void)testFunc:(NSString**)str;
Q34. What is printed from this code execution?
typedef enum {
thing1,
thing2,
thing3
} Thing;
-(void) enumStuff {
NSLog(@"%d", thing2);
}
Q35. You are worried about threaded access to a property and possible collision in writing. What directive should you use on the property?
Q36. What is wrong with this line of code?
int temp = 1==1;
Q37. What is special about the code within this block?
dispatch_async(dispatch_get_main_queue(), ^{
// code
});
Q38. How many items are in set1 after this code executes?
NSMutableSet *set1 = [NSMutableSet setWithObjects: @1,@2, @3, @4, @5, nil];
[set1 add0bject:@3];
Q39. What is wrong with this code?
NSDictionary *d1 = @[@"v1", @4, @"v2", @5.6, @"v3"];
NSlog(@"d1: %@", d1);
Q40. What is the initial value of the property val?
@property (nonatomic, readonly) int val;
Q41. Which thread should UI updates be processed on to avoid crashes and application lag?
Q42. What is the value of val after this code is executed?
NSString *val = @"1.23";
BOOL tf = val.boolValue;
Q43. In this code, what does ThatOne refer to?
@interface TestClass : ThisOne <ThatOne>
Q44. What is the value of result after this code is executed?
NSString *result = [Ftest"
stringByTrimmingCharactersInSet.NSCharacterSet.alphanumericCharacterSet];
Q45. When will self receive the notification based on this code?
MyClass .classObj = [[MyClass allot] init];
[class0bj add0bserver:self forKeyPath:@"name"
options:NSKeyValueObservingOptionNew context:NULL];
Q46. What is wrong with this code?
[*"true" boolValue];
Q47. How many times does this loop execute?
int loopVal = 0;
for (int i=0; i>loopVal; i--){
i--;
}
Q48. What will this code print?
NSLog(@"%lu", @"test".length);
Q49. What is the value of numVtoInt after this code is executed?
NSNumber *numV = [NSNumber numberWithFloat:6.7];
int numVtoInt = numV.intValue;
Q50. What does this code print?
NSString *val = @"1.23";
NSLog(@"%.04f", val.floatValue);
Q51. What is the maximum possible value of r1 in this code?
int r1 = arc4random() % 10;