Pages

Friday, March 18, 2016

iOS Programming Upwork Test Answer

1. Consider the following code:
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Set Background Color/Pattern
self.window.backgroundColor = [UIColor blackColor];
self.tabBarController.tabBar.backgroundColor = [UIColor clearColor];
//self.window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@”testbg.png”]];
// Set StatusBar Color
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
// Add the tab bar controller’s current view as a subview of the window
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
How can the error be corrected that gets thrown in the console, “Applications are expected to have a root view controller at the end of application launch”?
Answers:
  1. self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
  2. MenuViewController *menuViewController = [[MenuViewController alloc]init]; self.window.rootViewController = menuViewController;
  3. Both
  4. None of above
2. Which of the following allows it to determine if an application is running on iPhone, or if it’s running on an iPod Touch?
Answers:
  1. NSString *deviceType = [UIDevice currentDevice].model; if([deviceType isEqualToString:@”iPhone”])
  2. NSString *deviceType = [UIDevice currentDevice].Size; if([deviceType isEqualToString:@”iPhone”])
  3. NSString *deviceType = [UIDevice currentDevice].device; if([deviceType isEqualToString:@”Device”])
  4. NSString *deviceType = [UIDevice currentDevice].iPhone; if([deviceType isEqualToString:@”iPhone”])
3. What is true about ARC and manual memory management?
Answers:
  1. Always nil out properties in dealloc under ARC and manual memory management.
  2. Do not have to nil out properties in dealloc under ARC and manual memory management.
  3. nil out properties in dealloc under ARC but not in manual memory management.
  4. nil out properties in dealloc under manual memory management but not in ARC.
4. What does the “strong” property attribute do?
Answers:
  1. It does not extend the lifetime of the object it points to, and automatically becomes nil.
  2. It specifies a reference that does not keep the referenced object alive and is not set to nil.
  3. It makes the object alive, as long as there is a strong pointer to it.
  4. It specifies a reference that does not keep the referenced object alive and is not set to nil.
5. Which of the following is the best practice to find an active internet connection?
Answers:
  1. – (BOOL) connectedToInternet { Reachability *reachability = [Reachability reachabilityForInternetConnection]; NetworkStatus networkStatus = [reachability currentReachabilityStatus]; return !(networkStatus == NotReachable); }
  2. – (BOOL) connectedToInternet { NSString *URLString = [NSString stringWithContentsOfURL:[NSURL URLWithString:@”http://www.google.com”]]; return ( URLString != NULL ) ? YES : NO; }
  3. – (BOOL) connectedToInternet { NSURL *URLString = [NSURL URLWithString:@”http://www.google.com”]; NSData *data = [NSData dataWithContentsOfURL:URLString]; if (data) return YES; else return NO; }
  4. – (BOOL) connectedToInternet { NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:@”http://www.google.com/”]]; [request setHTTPMethod:@”HEAD”]; NSHTTPURLResponse *response; [NSURLConnection sendSynchronousRequest:request returningResponse:&response error: NULL]; return ([response statusCode] == 200) ? YES : NO; }
6. What gets returned if XIB is not properly connected to a parent controller?
Answers:
  1. EXEC_BAD_ACCESS
  2. SIGABRT
  3. SIGKILL
  4. None of these.
7. What is the use of performSelector in iOS?
Answers:
  1. To add a class delegate
  2. To define a class
  3. To call a method of a class
  4. To add a selector method
8. Which of the following is the correct way to get the value of the first object of a NsMutableArray stored in another NsMutableArray?
Answers:
  1. [[myArray objectAtIndex:0] objectAtIndex:0];
  2. [myArray objectAtIndex:0]
  3. [[[myArray objectAtIndex:0] objectAtIndex:0]objectAtIndex:0];
  4. [myArray firstObject]
9. What is the maximum size of an iOS application?
Answers:
  1. 20 MB
  2. 50 MB
  3. 1 GB
  4. 2 GB
10. Which of the following is the correct way to set the font size of UIButton title label?
Answers:
  1. someButton.font = [UIFont systemFontOfSize: 15];
  2. someButton.titleLabel.font = [UIFont systemFontOfSize: 15];
  3. [someButton setFont: [UIFont systemFontOfSize: 15]];
  4. All of the above
11. Which of the following frameworks is needed to apply a border to an object?
Answers:
  1. UIKit
  2. CoreGraphics
  3. QuartzCore
  4. Foundation
12. How can it be detected if the app is running on an iPhone 5?
Answers:
  1. if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone5)
  2. if([[UIScreen mainScreen] bounds].size.height == 568)
  3. if([[UIScreen mainScreen] bounds].size.height == 1136)
  4. if([[UIDevice currentDevice].model isEqualToString:@”iPhone5″])
13. Which of the following is not a valid Touch method with respect to Cocoa Touch programming?
Answers:
  1. – (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  2. – (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
  3. – (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
  4. None of above
14. Which of the following will return the device’s current location?
Answers:
  1. CLLocationManager locationManager = [[CLLocationManager alloc] init]; [locationManager startUpdatingLocation];
  2. CLLocationManager locationManager = [[CLLocationManager alloc] init]; [locationManager updateLocation];
  3. CLLocationManager locationManager = [[CLLocationManager alloc] init]; [locationManager getLocation];
  4. CLLocationManager locationManager = [[CLLocationManager alloc] init]; [locationManager findLocation];
15. Which of the following is the correct way to print out stack/trace to the console/log in Cocoa application?
Answers:
  1. NSLog(@”%@”,[NSThread callStackSymbols]);
  2. NSLog(@”%@”,[NSThread callStackReturnAddresses ])
  3. NSLog(@”%@”,[NSThread currentThread]);
  4. None of the above.
16. Which of the following is not a valid UIGestureRecognizer?
Answers:
  1. UITapGestureRecognizer
  2. UIZoomGestureRecognizer
  3. UIRotationGestureRecognizer
  4. UIPanGestureRecognizer
17. Which of the following will change the placeholder text color in UITextField?
Answers:
  1. textField.placeHolder.textColor = [UIColor redColor];
  2. textField.placeHolder.textLabel.textColor = [UIColor redColor];
  3. textField.placeHolder.color = [UIColor redColor];
  4. None of the above.
18. Which of the following framework is needed to round corners of UILabel?
Answers:
  1. UIKit
  2. CoreGraphics
  3. QuartzCore
  4. CoreAnimation
19. Which of the following is not a valid icon size for any iOS device (iPhone, iPod, iPad)?
Answers:
  1. 114 x 114
  2. 144 x 144
  3. 72 x 72
  4. 64 x 64
20. Which of the following is not a valid UIGestureRecognizer?
Answers:
  1. UITapGestureRecognizer
  2. UIZoomGestureRecognizer
  3. UIRotationGestureRecognizer
  4. UIPanGestureRecognizer
21. Which of the following will set an image on UIButton?
Answers:
  1. button.image = [UIImage imageNamed:@”btn_img.png”];
  2. button.imageView.image = [UIImage imageNamed:@”btn_img.png”];
  3. [button setImage:[UIImage imageNamed:@”btn_img.png”] forState:UIControlStateNormal];
  4. [button setImageView:[UIImage imageNamed:@”btn_img.png”] forState:UIControlStateNormal];
22. Select all incorrect bundle ID(s):
Answers:
  1. com.company.appName
  2. com.appName
  3. appName
  4. com.company-name.app-name
23. Which of the following will set the font of UISegmentedControl?
Answers:
  1. UIFont *font = [UIFont boldSystemFontOfSize:12.0f]; NSDictionary *attributes = [NSDictionary dictionaryWithObject:font forKey:UITextAttributeFont]; [segmentedControl setTitleTextAttributes:attributes forState:UIControlStateNormal];
  2. [[UISegmentedControl appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@”STHeitiSC-Medium” size:13.0], UITextAttributeFont, nil] forState:UIControlStateNormal];
  3. segmentedControl.transform = CGAffineTransformMakeScale(.6f, .6f);
  4. None of these.
24. Which of the following correctly sets an image on UIButton?
Answers:
  1. button.image = [UIImage imageNamed:@”button_img.png”];
  2. button.imageView.image = [UIImage imageNamed:@”button_img.png”];
  3. [button setImage:[UIImage imageNamed:@”button_img.png”] forState:UIControlStateNormal];
  4. [button setImageView:[UIImage imageNamed:@”button_img.png”] forState:UIControlStateNormal];
25. Which of the following font packages are supported by Cocoa-Touch?
Answers:
  1. .ttf (True Type Font)
  2. .ttc (True Type font Collection)
  3. .otf (Open Type Font)
  4. .dFont (MAC OS X Data Fork Font)
26. Which of the following is not an Open Source Framework/Library?
Answers:
  1. MBProgressHUD
  2. ASIHTTPRequest
  3. RestKit
  4. StoreKit
27. Which of the following is the best way to add a UIToolbar above keyboard?
Answers:
  1. -(void)keyboardWillShow:(NSNotification *)notification { [self.view addSubview:toolbar]; }
  2. -(void)textFieldDidBeginEditing:(UITextField *)textField { [self.view addSubview:toolbar]; }
  3. Always keep UIToolBar visible on screen.
  4. -(void)keyboardWillHide:(NSNotification *)notification { [self.view addSubview:toolbar]; }
28. Select which of the following is not UITableViewCellSelectionStyle values?
Answers:
  1. UITableViewCellSelectionStyleNone
  2. UITableViewCellSelectionStyleBlue
  3. UITableViewCellSelectionStyleLightGray
  4. UITableViewCellSelectionStyletGray
29. What is the correct method to define a delegate object in an ARC Environment?
Answers:
  1. @property (nonatomic, weak) id <MyClassDelegate> delegate;
  2. @property(nonatomic,retain) id <MyClassDelegate> delegate;
  3. @property(nonatomic,weak) <MyClassDelegate> delegate;
  4. @property(nonatomic, weak) NSObject *delegate;
30. Which of the following is the best practice to find active internet connection?
Answers:
  1. – (BOOL) connectedToInternet { Reachability *reachability = [Reachability reachabilityForInternetConnection]; NetworkStatus networkStatus = [reachability currentReachabilityStatus]; return !(networkStatus == NotReachable); }
  2. – (BOOL) connectedToInternet { NSString *URLString = [NSString stringWithContentsOfURL:[NSURL URLWithString:@”http://www.google.com”]]; return ( URLString != NULL ) ? YES : NO; }
  3. – (BOOL) connectedToInternet { NSURL *URLString = [NSURL URLWithString:@”http://www.google.com”]; NSData *data = [NSData dataWithContentsOfURL:URLString]; if (data) return YES; else return NO; }
  4. – (BOOL) connectedToInternet { NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:@”http://www.google.com/”]]; [request setHTTPMethod:@”HEAD”]; NSHTTPURLResponse *response; [NSURLConnection sendSynchronousRequest:request returningResponse:&response error: NULL]; return ([response statusCode] == 200) ? YES : NO; }
31. What will be output of following code?
NSLog(@”%.2f”,[[UIDevice currentDevice].systemVersion floatValue]);
Answers:
  1. 6.1.0
  2. 6.1.2
  3. 6.10
  4. 6.12
32. What is the difference between new and [[alloc]init] in iOS?
Answers:
  1. [[alloc]init] is used to create an object but new is not used to create an object.
  2. Neither [[alloc]init] nor new is used for creating an object.
  3. No difference. Both [[alloc]init] and new are used to create an object.
  4. [[alloc]init] is not used to create object but new is used to an create object.
33. How can the application name of an iOS project be changed?
Answers:
  1. Change Bundle Display Name from info.plist
  2. Rename Project
  3. Change bundle identifier
  4. Create a new project with New name
34. What could be the probable result if selector is unknown or undefined?
Answers:
  1. Causes memory leak
  2. Causes application to terminate with error
  3. Nothing will happen
  4. None of above
35. Is it possible to deploy beta build on any device?
Answers:
  1. Yes beta build can be deployed on any iOS device.
  2. Beta build can be deployed only on devices that are included in Mobile Provision certificate while compiling build.
  3. Beta Build can be deployed only on Simulators.
  4. All of above
36. Which one is true regarding integrating and using custom fonts in an iOS application?
Answers:
  1. Apple rejects the applications that use custom fonts.
  2. Adding fonts to your app plist allows usage directly in the app.
  3. There is no direct way to add fonts; third party APIs are the only way.
  4. You can add fonts, but only if they are provided by Apple.
37. Which of the following is the correct way to set UIButton’s Highlight Tint color programmatically?
Answers:
  1. [button setColor:[UIColor grayColor]];
  2. [button setTintColor:[UIColor grayColor]];
  3. [button setColor:[UIColor grayColor]];
  4. [button TintColor:[UIColor grayColor]];
38. Which of the following properties would be used to draw a shadow under UIView?
Answers:
  1. CGContextRestoreShadowState
  2. CGContextRestoreGState
  3. CGContextSetShadow();
  4. CGContextshadowState
39. Which of the following is the correct way to check whether the view controller view is loaded or visible?
Answers:
  1. if (viewController.isViewLoaded || tabbarController.view.window) { // viewController is visible }
  2. if([[[self tabBarController] selectedViewController] isEqual:self]){ //we’re in the active controller }else{ //we are not }
  3. if (viewController.isLoaded && viewController.view.) { // viewController is visible }
  4. if (viewController.isViewLoaded && viewController.view.window) { // viewController is visible }
40. Which of the following is the correct way to transfer data from one view controller to another?
Answers:
  1. EditingViewController *controller = [[EditingViewController alloc] initWithNibName:@”EditingView” bundle:nil]; controller.editedObject = book; … [self.navigationController pushViewController:controller animated:YES]; [controller release]; In the Editing View (EditingViewController): – (IBAction)save { … [editedObject setValue:datePicker.date forKey:editedFieldKey]; [editedObject setValue:textField.text forKey:editedFieldKey]; } [self.navigationController popViewControllerAnimated:YES]; }
  2. NSString *commString; in appDelegate. And then when you submit the uitextfield value just assign that text field value to the appDelegate.commString use this in the next view. ProjectNameAppDelegate *appDelegate = [[UIApplication sharedApplicatoin] delegate]; appDelegate.commString = textField.text;
  3. Both 1 and 2 methods are correct.
  4. None of above are correct.
41. Which of the following UILabel properties help adjust text within a UILabel?
Answers:
  1. lineBreakMode
  2. adjustsFontSizeToFitWidth
  3. numberOfLines
  4. drawTextInRect:
42. Which of the following is the correct way to set the Navigation Bar Color of the Tab Bar Configure Menu?
Answers:
  1. “UINavigationController *navigationController; … navigationController.navigationBar.tintColor = [UIColor blackColor];”
  2. “UINavigationController *navigationController; … navigationController.tintColor = [UIColor blackColor];”
  3. “UINavigationController *navigationController; … navigationController.color = [UIColor blackColor];”
  4. “UINavigationController *navigationController; … navigationController.navigationBar.Color = [UIColor blackColor];”
43. What does EXC_BAD_ACCESS signal received mean in Xcode?
Answers:
  1. Due to warning in code
  2. “Owning” the memory but forgetting to release
  3. Testing on a device without registering UDID
  4. Using incorrect delegate methods
44. Which of the following is best JSON library to be used in iOS applications?
Answers:
  1. SBJSON
  2. JSON kit
  3. Touch JSON
  4. None of these
45. How can an SMS be sent programmatically from the iPhone (iOS 4.0 or later)?
Answers:
  1. Using MFMessageComposeViewController
  2. [[UIApplication sharedApplication] openURL: @”sms:PHONE-NUMBER”];
  3. Both A &B are correct answers
  4. The official SDK/Cocoa Touch doesn’t allow sending SMSs programmatically
46. What is the difference between assign and retain in Objective-C?
Answers:
  1. assign – Specifies that a copy of the object should be used for assignment. The previous value is sent a release message. retain – Specifies that the setter uses simple assignment. The previous value is sent a release message.
  2. assign – Specifies that the setter uses simple assignment. This is the default. retain – Specifies that retain should be invoked on the object upon assignment. The previous value is sent a release message.
  3. assign – Increases the count of an object by 1. Takes ownership of an object. retain – Decreases the retain count of an object by 1. Relinquishes ownership of an object.
  4. assign – Makes a assign of an object, and returns it with retain count of 1. If you copy an object, you own the copy. retain – Specifies that a retain of the object should be used for assignment. The previous value is sent a release message.
47. Which property would be used to get the UDID of UIDevice on iOS?
Answers:
  1. [UIDevice UDIDString]
  2. [UIDevice uniqueIdentifier]
  3. -[UIDevice identifierForVendor]
  4. None of these
48. When does this behavior usually happen?
“Xcode Message: finished running <my app>” on targeted device shows, but nothing happens
Answers:
  1. If the app was ran on earlier devices (3G or 3GS) and arm6 was not added in Require Device Capabilities.
  2. If app was built and ran on version 3.2 or earlier of Xcode and arm7 was not added in Require Device Capabilities.
  3. If Bundle Identifier used in the project is being used by another project
  4. When some another application is already running on device
  5. When the device is locked with a passcode
49. Is it possible to set multiple architecture from Build Settings tab in Xcode for a project?
Answers:
  1. Yes
  2. No
  3. only in Xcode 4.5 or later
  4. only in Xcode 4.5 or previous
50. Which framework can be used to call SOAP web services in iOS applications?
Answers:
  1. gSOAP
  2. ASIHTTP framework
  3. wsdl2objc framework
  4. None of these
51. What property in info.plist handles the association of file types in an iPhone application?
Answers:
  1. LSItemContentTypes
  2. LSHandlerRank
  3. CFBundleTypeName
  4. CFBundleTypeRole
52. Which method of Objective-C handles detecting the shake gesture on an iOS device?
Answers:
  1. + (UIAccelerometer *)sharedAccelerometer
  2. – (void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
  3. – (void) accelerometer:(UIAccelerometer *)accelerometer willAccelerate:(UIAcceleration *)acceleration
  4. – (void) accelerometer:(UIAccelerometer *)accelerometer beginAccelerate:(UIAcceleration *)acceleration
53. Which one is the best resolution for the following error?
“A valid signing identity matching this profile could not be found in your keychain”
Answers:
  1. Installing the certificate file in your keychain
  2. Renewing your provisioning profile
  3. Installing the private key in your keychain
  4. Renewing your Apple developer account.
54. What is the best way to show multiple lines text in the UILabel?
Answers:
  1. CGRect currentFrame = myLabel.frame; CGSize max = CGSizeMake(myLabel.frame.size.width, 500); label.font = [UIFont systemFontOfSize:13.0]; CGSize expected = [myString sizeWithFont:myLabel.font]; myLabel.numberOfLines = 0;
  2. CGRect currentFrame = myLabel.frame; CGSize max = CGSizeMake(myLabel.frame.size.width, -1); CGSize expected = [myString sizeWithFont:myLabel.font]; myLabel.numberOfLines = -1;
  3. myLabel.numberOfLines = 0; CGRect currentFrame = myLabel.frame; CGSize max = CGSizeMake(myLabel.frame.size.width, 500); CGSize expected = [myString sizeWithFont:myLabel.font constrainedToSize:max lineBreakMode:myLabel.lineBreakMode]; currentFrame.size.height = expected.height; myLabel.frame = currentFrame;
  4. You have to use UITextView for this purpose, otherwise Apple will rejects your app submission
55. Which of the following correctly describes when the – (void)viewDidUnload method is called?
Answers:
  1. When the application launches.
  2. When any view appears.
  3. When a view is released.
  4. During low memory conditions when the view controller needs to release its view.
56. Which of the following is not a valid MKAnnotationView property?
Answers:
  1. canShowCallout
  2. draggable
  3. dragState
  4. None of these.
57. What does a “__block” type specifier mean?
Answers:
  1. Modifications made with the variable marked with __block inside the block are not visible outside of it.
  2. Modifications done with the variable marked with __block inside the block are also visible outside of it.
  3. It makes the variable non-mutable within the block.
  4. None of the above
58. Which of the following is not a valid MPVolumeView method?
Answers:
  1. – (CGRect)volumeThumbRectForBounds:(CGRect)bounds volumeSliderRect:(CGRect)rect value:(float)value
  2. – (UIImage *)maximumVolumeSliderImageForState:(UIControlState)state
  3. – (CGRect)routeButtonRectForBounds:(CGRect)bounds
  4. – (void)setVolumeThumbImage:(UIImage *)image
59. Which of the following code samples will declare a variable inside a block in Objective-C?
Answers:
  1. Person *aPerson = nil; [participants enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { Person *participant = (Person*)obj; if ([participant.gender isEqualToString:@”M”]) { aPerson = participant; *stop = YES; } }]; return aPerson;
  2. __block Person *aPerson = nil; [participants enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { Person *participant = (Person*)obj; if ([participant.gender isEqualToString:@”M”]) { aPerson = participant; *stop = YES; } }]; return aPerson;
  3. [participants enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { Person *participant = (Person*)obj; Person *aPerson = nil; if ([participant.gender isEqualToString:@”M”]) { aPerson = participant; *stop = YES; } }]; return aPerson;
  4. All of the above.

No comments:

Post a Comment