[iOS] Technical Interview possible question – 01

Suppose that we have a ViewController.h and .m like this:

[code lang=”csharp” autolinks=”false” collapse=”false” firstline=”1″ gutter=”true” htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”false”]// ViewController.h
#import UIKit/UIKit.h</code>

@interface ViewController : UIViewController
@end
// ViewController.m
#import "ViewController.h"
#import "SetValue.h"

@implementation ViewController
– (void)viewDidLoad
{
[super viewDidLoad];
[SetValue SetTheValue:@"a string"];
}
@end[/code]

And a class called SetValue, with two methods.

[code lang=”csharp” autolinks=”false” collapse=”false” firstline=”1″ gutter=”true” htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”false”]// SetValue.h
#import Foundation/Foundation.h
@interface SetValue : NSObject { }

+ (void) SetTheValue:(id)Obj;
– (void) MySelector:(id)Obj;

@end

// SetValue.m
#import "SetValue.h"
@implementation SetValue

+ (void) SetTheValue:(id)Obj
{
[self performSelectorOnMainThread:@selector(MySelector:)
withObject:Obj
waitUntilDone:NO];
}

– (void) MySelector:(id)Obj
{
NSLog(@"Data: %@", [Obj description]);
}

@end[/code]

What is the value printed by the NSLog?

enjoy.

Ref: albertopasca.it

 

Alberto Pasca

Software engineer @ Pirelli & C. S.p.A. with a strong passion for mobile  development, security, and connected things.