MCQs > IT & Programming > Swift MCQs > Basic Swift MCQs

Basic Swift MCQ

1. How can you extract val to x in tuple vt? let vt = (name: "ABC", val: 5)

Answer

Correct Answer: All of these answers

Note: This Question is unanswered, help us to find answer for this one

2. What is the type of vals in this code? let vals = ["a", 1, "Hi"]

Answer

Correct Answer: [Any]

Note: This Question is unanswered, help us to find answer for this one

3. What is the value of numbers in the code below? let numbers = [1,2,3,4,5,6].filter{ $0 % 2 == 0}

Answer

Correct Answer: [2,4,6]

Note: This Question is unanswered, help us to find answer for this one

4. In the code below, AOM must be a(n)? class AmP : MMM, AOM { }

Answer

Correct Answer: Protocol

Note: This Question is unanswered, help us to find answer for this one

5. What enumeration feature allows them to store case-specific data? (Question does not make that much sense though. )

Answer

Correct Answer: Associated values

Note: This Question is unanswered, help us to find answer for this one

6. What is printed to the console when this code is executed? "t".forEach { (char) in; print(char) }

Answer

Correct Answer: t

Note: This Question is unanswered, help us to find answer for this one

7. What is the value of val after this code is executed? let i = 5; let val = i * 6.0

Answer

Correct Answer: This code is invalid.

Note: This Question is unanswered, help us to find answer for this one

8. What is true of this code? let name: String?

Answer

Correct Answer: Name can hold either a string or nil value.

Note: This Question is unanswered, help us to find answer for this one

9. What does this code print? let names = ["Bear", "Tony", "Svante"] print(names[1]+"Bear")

Answer

Correct Answer: TonyBear

Note: This Question is unanswered, help us to find answer for this one

10. How many times this code will be executed? —OR— How many times will this loop be performed? for i in ["0", "1"]{print(i)}

Answer

Correct Answer: Two

Note: This Question is unanswered, help us to find answer for this one

11. How do you declare an optional String?

Answer

Correct Answer: String?

Note: This Question is unanswered, help us to find answer for this one

12. When is deinit called?

Answer

Correct Answer: All of these answers

Note: This Question is unanswered, help us to find answer for this one

13. DispatchQueue.main.async takes a block that will be

Answer

Correct Answer: Executed in the main queue

Note: This Question is unanswered, help us to find answer for this one

14. How can you sort this array?

Answer

Correct Answer: All of these answers

Note: This Question is unanswered, help us to find answer for this one

15. What prints to the console when executing this code? let x = try? String.init("test") print(x)

Answer

Correct Answer: Optional("test")

Note: This Question is unanswered, help us to find answer for this one

16. What is wrong with this code? Let val = 5.0 + 10

Answer

Correct Answer: There is nothing wrong with this code

Note: This Question is unanswered, help us to find answer for this one

17. What is wrong with this code? var x = 5; x = 10.0

Answer

Correct Answer: You cannot assign a Double to a variable of type Int

Note: This Question is unanswered, help us to find answer for this one

18. What data type is this an example of? let vals = ("val", 1)

Answer

Correct Answer: A tuple

Note: This Question is unanswered, help us to find answer for this one

19. Which of these choices is associated with unit testing?

Answer

Correct Answer: All of these answers

Note: This Question is unanswered, help us to find answer for this one

20. What is wrong with this code? for (key, value) in [1: "one", 2: "two"]{print(key, value)}

Answer

Correct Answer: There is nothing wrong with this code

Note: This Question is unanswered, help us to find answer for this one

21. In the function below, what are this and toThat examples of? func add(this x: Int, toThat y: Int)->{}

Answer

Correct Answer: Argument labels

Note: This Question is unanswered, help us to find answer for this one

22. How do you designated a failable initializer?

Answer

Correct Answer: Init?

Note: This Question is unanswered, help us to find answer for this one

23. How would you call a function that throws errors and also returns a value?

Answer

Correct Answer: Try?

Note: This Question is unanswered, help us to find answer for this one

24. What is the inferred type of x? let x = ["a", "b", "c"]

Answer

Correct Answer: Array

Note: This Question is unanswered, help us to find answer for this one

25. Which object allows you access to specify that a block of code runs in a background thread?

Answer

Correct Answer: DispatchQueue.global

Note: This Question is unanswered, help us to find answer for this one

26. What must a convenience initializer call?

Answer

Correct Answer: A designated initializer

Note: This Question is unanswered, help us to find answer for this one

27. What is the base class in this code? class LSN : MMM {}

Answer

Correct Answer: MMM

Note: This Question is unanswered, help us to find answer for this one

28. What is the value of test after this code executes? let vt = (name: "ABC", val: 5) let test = vt.0

Answer

Correct Answer: ABC

Note: This Question is unanswered, help us to find answer for this one

29. What is the value of t after this code is executed? let names = ["Larry", "Sven", "Bear"] let t = names.enumerated().first().offset

Answer

Correct Answer: This code is invalid.
This code does not compile.

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

30. What can AnyObject represent?

Answer

Correct Answer: All of these answers

Note: This Question is unanswered, help us to find answer for this one

31. How many times will this loop be executed? for i in 0...100 {print(i)}

Answer

Correct Answer: 101

Note: This Question is unanswered, help us to find answer for this one

32. What is the correct way to add a value to this array? var strings = [1, 2, 3]

Answer

Correct Answer: All of these answers

Note: This Question is unanswered, help us to find answer for this one

33. All value types in Swift are _ under the hood?

Answer

Correct Answer: Structs

Note: This Question is unanswered, help us to find answer for this one

34. How do you reference class members from within a class?

Answer

Correct Answer: Self

Note: This Question is unanswered, help us to find answer for this one

35. Which code snippet correctly creates a typealias closure?

Answer

Correct Answer: Typealias CustomClosure: () -> ()

Note: This Question is unanswered, help us to find answer for this one

36. What is wrong with this code? if let s = String.init("some string") { print(s)}

Answer

Correct Answer: This String initializer does not return an optional.

Note: This Question is unanswered, help us to find answer for this one

37. How can you avoid a strong reference cycle in a closure?

Answer

Correct Answer: Use a capture list to set class instances of weak or unowned.

Note: This Question is unanswered, help us to find answer for this one

38. How many values does vals have after this code is executed? var vals = Set = ["4", "5", "6"] vals.insert("5")

Answer

Correct Answer: This code contains an error.

Note: This Question is unanswered, help us to find answer for this one

39. DidSet and willSet are examples of _?

Answer

Correct Answer: Property observers

Note: This Question is unanswered, help us to find answer for this one

40. What describes this line of code? let val = 5

Answer

Correct Answer: A constant named val of type Int

Note: This Question is unanswered, help us to find answer for this one

41. When a function takes a closure as a parameter, when do you want to mark is as escaping?

Answer

Correct Answer: When it's executed after the function returns

Note: This Question is unanswered, help us to find answer for this one

42. What is the type of value1 in this code? let value1 = "\("test".count)"

Answer

Correct Answer: String

Note: This Question is unanswered, help us to find answer for this one

43. The Codable protocol is _?

Answer

Correct Answer: A combination of Encodable and Decodable

Note: This Question is unanswered, help us to find answer for this one

44. What is the correct way to call this function? func myFunc(_ a: Int, b: Int) -> Int {return a + b}

Answer

Correct Answer: MyFunc(5, b: 6)

Note: This Question is unanswered, help us to find answer for this one

45. What is the type of this function? func add(a: Int, b: Int) -> Int { return a+b }

Answer

Correct Answer: (Int, Int) -> Int

Note: This Question is unanswered, help us to find answer for this one

46. What is the value of y? var x: Int? let y = x ?? 5

Answer

Correct Answer: 5

Note: This Question is unanswered, help us to find answer for this one

47. What is the value of test in this code? var test = 1 == 1

Answer

Correct Answer: TRUE

Note: This Question is unanswered, help us to find answer for this one

48. What is the value of y? let x = ["1", "2"].dropFirst() let y = x[0]

Answer

Correct Answer: This code contains an error

Note: This Question is unanswered, help us to find answer for this one

49. Why is dispatchGroup used in certain situations?

Answer

Correct Answer: All of these answers.

Note: This Question is unanswered, help us to find answer for this one

50. What is the raw/underlying type of this enum? enum Direction {case north, south, east, west}

Answer

Correct Answer: There is none.

Note: This Question is unanswered, help us to find answer for this one

51. What is the error in this code? let x = 5; guard x == 5 { return }

Answer

Correct Answer: The guard is missing the else.

Note: This Question is unanswered, help us to find answer for this one

52. What is this code an example of? let val = (Double)6

Answer

Correct Answer: A syntax issue

Note: This Question is unanswered, help us to find answer for this one

53. Typical range of type Int8 is __

Answer

Correct Answer: -128 to 127

Note: This Question is unanswered, help us to find answer for this one

54. The following are unordered collection types:

Answer

Correct Answer: Dictionary and Set

Note: This Question is unanswered, help us to find answer for this one

55. A sequence of characters surrounded by double quotes is called _____?

Answer

Correct Answer: String Literal

Note: This Question is unanswered, help us to find answer for this one

56. Can cyclical relationships exist in value types?

Answer

Correct Answer: No

Note: This Question is unanswered, help us to find answer for this one

57. A closure is a function without a name.

Answer

Correct Answer: True

Note: This Question is unanswered, help us to find answer for this one

58.

var varB = 3.14159ng is the c

varB is inferred to be of type _____

Answer

Correct Answer: Double

Note: This Question is unanswered, help us to find answer for this one

59. print(myStr) What will be the output of the above code snippet in Swift4?

Answer

Correct Answer: Hello
World!

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

60.

var myVar = 100

myVar = "Hello World"

print(varA)

The output will be

Answer

Correct Answer: Compile time error

Note: This Question is unanswered, help us to find answer for this one

61. We can create an array of any type

Answer

Correct Answer: True

Note: This Question is unanswered, help us to find answer for this one

62. Which is the correct naming scheme for an Objective-C bridging header file into Swift project

Answer

Correct Answer: ProjectName-Bridging-Header.h

Note: This Question is unanswered, help us to find answer for this one

63. Bridging header file will not be compiled due to the following issues:

Answer

Correct Answer: Both

Note: This Question is unanswered, help us to find answer for this one

64. Objective-C class factory methods will change into _____ after importing to Swift

Answer

Correct Answer: Convenience initializer

Note: This Question is unanswered, help us to find answer for this one

65. Overriding functionality is possible using extension

Answer

Correct Answer: True

Note: This Question is unanswered, help us to find answer for this one

66. New initializers can be provided using extension

Answer

Correct Answer: True

Note: This Question is unanswered, help us to find answer for this one

67. What is the correct way to import an Objective-C class into bridging header file?

Answer

Correct Answer: #import "CustomObject.h"

Note: This Question is unanswered, help us to find answer for this one

68.

The following are collection types in Swift

Note: There may be more than one right answer.

Answer

Correct Answer: String
Array
Dictionary
Set

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

69.

var myName: Int = "John Doe"

print(myName)

The output will be

Answer

Correct Answer: Compile-time error

Note: This Question is unanswered, help us to find answer for this one

70.

The 'let' keyword is considered as:

Note: There may be more than one right answer.

Answer

Correct Answer: Constant
read only
Thread safe

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

71. How can you create a new name for an existing type in Swift?

Answer

Correct Answer: Typealias

Note: This Question is unanswered, help us to find answer for this one

72.

In Swift, private properties of a class can be accessed in any of it's extension.

Answer

Correct Answer: False

Note: This Question is unanswered, help us to find answer for this one

73. Can you pass Int to a String type variable?

Answer

Correct Answer: False

Note: This Question is unanswered, help us to find answer for this one

74. Which of the following do you need to serialize and archive your custom types in Swift?

Answer

Correct Answer: Implement the Codable protocol

Note: This Question is unanswered, help us to find answer for this one

75. Stage when memory returned to stack or heap?

Answer

Correct Answer: Deallocation

Note: This Question is unanswered, help us to find answer for this one

76. During which stage memory is taken from stack or heap?

Answer

Correct Answer: Allocation

Note: This Question is unanswered, help us to find answer for this one

77. What is the typical byte width of Float data type in Swift?

Answer

Correct Answer: 4 bytes

Note: This Question is unanswered, help us to find answer for this one

78. Weak references are declared as _____ types

Answer

Correct Answer: Optional

Note: This Question is unanswered, help us to find answer for this one

79. unowned reference types are declared as __

Answer

Correct Answer: Non-optional

Note: This Question is unanswered, help us to find answer for this one

80. NSOperationQueue.mainQueue().addOperationWithBlock will add the operation to

Answer

Correct Answer: UI Thread

Note: This Question is unanswered, help us to find answer for this one

81. GCD provides the following types of Queues:

Answer

Correct Answer: All of the above

Note: This Question is unanswered, help us to find answer for this one

82. NSOperationQueue conforms to

Answer

Correct Answer: None

Note: This Question is unanswered, help us to find answer for this one

83. GCD can dispatch a task

Answer

Correct Answer: Both

Note: This Question is unanswered, help us to find answer for this one

84.

func addStudent(_ student: Student) {

  concurrentStudentQueue.async(flags: .barrier) { 

self._students.append(student) 

DispatchQueue.main.async { //

  self.postContentAddedNotification()

}

  }

}

The code will ensure that the submitted DispatchWorkItem will be executed in parallel with any other DispatchWorkItem in the same queue.

Answer

Correct Answer: False

Note: This Question is unanswered, help us to find answer for this one

85. GCD conforms with the ____ order.

Answer

Correct Answer: FIFO

Note: This Question is unanswered, help us to find answer for this one

86. A Switch statement cannot handle String.

Answer

Correct Answer: False

Note: This Question is unanswered, help us to find answer for this one

87. In which data types can you define methods?

Answer

Correct Answer: All

Note: This Question is unanswered, help us to find answer for this one

88. Swift allows you to write semicolons at the end of statement.

Answer

Correct Answer: True

Note: This Question is unanswered, help us to find answer for this one

89. If C is a superset of D, then D is a subset of C

Answer

Correct Answer: True

Note: This Question is unanswered, help us to find answer for this one

90. Which is true about the Dictionary?

Answer

Correct Answer: Keys and Values can be of different types

Note: This Question is unanswered, help us to find answer for this one

91.

Extension can be used to create a new nested type of the following:

Note: There may be more than one right answer.

Answer

Correct Answer: Class
Structure
Enumeration

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

92. Instance methods can be _____ in extension

Answer

Correct Answer: Mutating

Note: This Question is unanswered, help us to find answer for this one

93.

Which of the following are true about extension functionalities?

Note: There may be more than one right answer.

Answer

Correct Answer: They Can define instance and type methods.
They Can define subscripts
They Can define and use new nested types

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

94.

extension Int {

   subscript(var myInt: Int) -> Int {

  var no1 = 1

  while myInt > 0 {

     no1 *= 10

     --myInt

  }

  return (self / no1) % 10

   }

}

print(12[0])

What is the output?

Answer

Correct Answer:

2


Note: This Question is unanswered, help us to find answer for this one

95.

After importing Objective-C code to Swift, the above method will be imported as

(instancetype)initWithFrame:(CGRect)frame

                 style:(UITableViewStyle)style;

Answer

Correct Answer: init(frame: CGRect, style: UITableViewStyle) { }

Note: This Question is unanswered, help us to find answer for this one

96. Objective-C class can be instantiated in Swift class only through

Answer

Correct Answer: Swift initializer syntax.

Note: This Question is unanswered, help us to find answer for this one

97. Objective-C nullable properties will appear as __ properties when imported to Swift project.

Answer

Correct Answer: optional

Note: This Question is unanswered, help us to find answer for this one

98. Closures capture ____ reference of objects by default

Answer

Correct Answer: Strong

Note: This Question is unanswered, help us to find answer for this one

99. Please check following code and tell what can be problem? import UIKitvarintVar:Int?=3 intVar = nil varstrVar:StringstrVar = nil

Answer

Correct Answer: strVar cannot be initialized with nil

Note: This Question is unanswered, help us to find answer for this one

100. What does Swift compile to?

Answer

Correct Answer: Machine Code

Note: This Question is unanswered, help us to find answer for this one

101.

What is the correct way to import Objective-C files into Swift?

Answer

Correct Answer: Objective-C classes are imported via a Bridging Header.

Note: This Question is unanswered, help us to find answer for this one

102.

What is the return type of the following code? func nameFunc() -> String { return "Jhon" }

Answer

Correct Answer: String

Note: This Question is unanswered, help us to find answer for this one

103.

The following attribute can be used to allow a protocol to contain optional functions and to be used in ObjC?

Answer

Correct Answer: @objc

Note: This Question is unanswered, help us to find answer for this one

104.

Suppose below variable declaration, select a right answer? import UIKit var str = "string" var ŝanĝiĝema = "хувьсагч" var & = "&"

Answer

Correct Answer: 3rd declaration is invalid

Note: This Question is unanswered, help us to find answer for this one

105.

How can you fix the missing characters for the following code? func userScore -> Bool { return true }

Answer

Correct Answer: ()

Note: This Question is unanswered, help us to find answer for this one

106.

How to hide status bar in iOS app with Swift as follows?

Answer

Correct Answer: We need set UIApplication.sharedApplication().statusBarHidden=true; with viewWillAppear() function overriding

Note: This Question is unanswered, help us to find answer for this one

107.

Which of the following is an appropriate syntax for dispatching a heavy operation to a background thread?

Answer

Correct Answer: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), { self.heavyOperation() })

Note: This Question is unanswered, help us to find answer for this one

108.

If a class is named 'MyClass' with a nested enum called 'Status', how do you indicate that a variable is an enum of type 'Status' outside the context of 'MyClass'? class MyClass { enum Status { case On, Off } }

Answer

Correct Answer: var status: MyClass.Status = .On

Note: This Question is unanswered, help us to find answer for this one

109.

What is the output when following code is executed? import UIKit import AVFoundation var p: AVAudioPlayer? func func(filename:String) { let url = NSBundle.mainBundle().URLForResource(filename, withExtension: "caf")! do { p = try AVAudioPlayer(contentsOfURL: url) guard let p = p else { return } … … … p.prepareToPlay() p.play() } catch let error as NSError { print(error.description) } }

Answer

Correct Answer: Plays audio caf file in the resource folder of the bundle

Note: This Question is unanswered, help us to find answer for this one

110.

Based on var index = UInt8.max, which of the following operation results to the value of zero for var index?

Answer

Correct Answer: index = index &+ 1

Note: This Question is unanswered, help us to find answer for this one

111.

Which of the following is the correct keyword for defining a constant in Swift?

Answer

Correct Answer: let

Note: This Question is unanswered, help us to find answer for this one

112.

The following keyword in the context of a Switch statement is required to force the execution of a subsequent case?

Answer

Correct Answer: fallthrough

Note: This Question is unanswered, help us to find answer for this one

113.

Which of the following statements is a valid way to extend the capabilities of our theoretical class, MyClass to conform to protocol MyProtocol?

Answer

Correct Answer: extension MyClass: MyProtocol { }

Note: This Question is unanswered, help us to find answer for this one

114.

In Swift, objects are usually references to instances for both _____ and classes?

Answer

Correct Answer: structures

Note: This Question is unanswered, help us to find answer for this one

115.

What is the return value of the type check operator - is ?

Answer

Correct Answer: true, false

Note: This Question is unanswered, help us to find answer for this one

116.

Which integer literals have a decimal value of 17? (choose all that apply)

Answer

Correct Answer: let decimalInteger = 17
let octalInteger = 0o21
let hexadecimalInteger = 0x11

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

117.

What is the correct way to declare Decomposed Tuple?

Answer

Correct Answer: let (a, b, c, d) = rectangle

Note: This Question is unanswered, help us to find answer for this one

118.

How do you remove items from arrays? (choose all that apply)

Answer

Correct Answer: arry.removeLast()
arry.removeAtIndex(0)
arry.removeAll(keepCapacity: false)

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

119.

What are the Numeric Integer Literals? (choose all that apply)

Answer

Correct Answer: A decimal number, with no prefix
A binary number, with a 0b prefix
An octal number, with a 0o prefix
A hexadecimal number, with a 0x prefix

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

120.

Which of the following is a correct answer for Enumerations?

Answer

Correct Answer: Enumerations can define initializers.

Note: This Question is unanswered, help us to find answer for this one

121.

How to extract a string from URL data?

Answer

Correct Answer: import UIKit var url = "http://www.google.com/ss.js?id=123456789"; var id = url.componentsSeparatedByString("id="); print(id[1]) ;

Note: This Question is unanswered, help us to find answer for this one

122.

Which of the following statements are true about Tuple?

Answer

Correct Answer: Group multiple values of any type into a single compound value

Note: This Question is unanswered, help us to find answer for this one

123.

In Swift, what are the benefits of classes?

Answer

Correct Answer: All of the above

Note: This Question is unanswered, help us to find answer for this one

124.

When the following code is executed, what it will do? funcfunc() { let layer = UIApplication.sharedApplication().keyWindow!.layer let scale = UIScreen.mainScreen().scale UIGraphicsBeginImageContextWithOptions(layer.frame.size, false, scale); layer.renderInContext(UIGraphicsGetCurrentContext()!) let s = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() UIImageWriteToSavedPhotosAlbum(s, nil, nil, nil) }

Answer

Correct Answer: It gets full screenshot and will save it as JPG file in photo folder

Note: This Question is unanswered, help us to find answer for this one

125.

Select the most proper answer. import UIKit import AVFoundation … … … let r:AVAudioRecorder? do { r = try AVAudioRecorder(URL: soundFileURL, settings: rSettings) r.delegate = self r.meteringEnabled = true r.prepareToRecord() } catch let error as NSError { r = nil print(error.localizedDescription) }

Answer

Correct Answer: It opens audio recording file, and prepares for the audio recording environment

Note: This Question is unanswered, help us to find answer for this one

126.

What is the need for having structures?

Answer

Correct Answer: All of them

Note: This Question is unanswered, help us to find answer for this one

127.

In Swift, what's the correct way variables consist?

Answer

Correct Answer: var> name > type > value

Note: This Question is unanswered, help us to find answer for this one

128.

On which tag background color for the page can be set?

Answer

Correct Answer: <body>

Note: This Question is unanswered, help us to find answer for this one

129.

Compare the below code and what will result?

import UIKit

var rank:Dictionary = [1:”First”, 2: “Second”, 3: “Third”];

rank.updateValue(“Forth”, forKey: 4);

rank[5]=”Fifth”;

for I in rank {

print(i);

}

import UIKit

var rank:Dictionary = [2:”Second”, 1: “First”, 3: “Third”];

rank[5]=”Fifth”;

rank.updateValue(“Forth”, forKey: 4);

for I in rank {

print(i)

}

Answer

Correct Answer: Output Result will be same

Note: This Question is unanswered, help us to find answer for this one

130.

Please check following code and tell what can be problem?

 import UIKit ;

var intVar:Int?=3;

 intVar = nil;

 var strVar:String;

 strVar = nil;

Answer

Correct Answer: strVar cannot be initialized with nil

Note: This Question is unanswered, help us to find answer for this one

131.

Execute below code and tell what can be problem? import UIKit let fm = NSFileManager.defaultManager() fm.removeItemAtPath("file.old")

Answer

Correct Answer: If it cannot find file, exception would be occurred, we need exception handling

Note: This Question is unanswered, help us to find answer for this one

132.

Use the classes defined above to create a new Person instance, and try to access its numberOfRooms property as before?

Answer

Correct Answer: let john = Person() if let roomCount = john.residence?.numberOfRooms { println("John's residence has \(roomCount) room(s).") }else{ println("Unable to retrieve the number of rooms.") }

Note: This Question is unanswered, help us to find answer for this one

133.

What does the following code?

import UIKit

var str1:String?="text1";

var str2:String="text2";

 var int1:Int?=111;

 var int2:Int=222;

 var array:String[] = [str1, str2, int1, int2];

 array=[];

Answer

Correct Answer: Str2 and int2 cannot be initialized because they are not optional variables.

Note: This Question is unanswered, help us to find answer for this one

134.

Extensions can add new instance ____?

Answer

Correct Answer: methods

Note: This Question is unanswered, help us to find answer for this one

135.

Consider the following code output when the file doesn’t exist?

import UIKit

 let filename:String = "testfile";

var readdata:String = "test data";

 let pathname = NSURL(fileURLWithPath: "..") URLByAppendingPathComponent(filename) ;

do {

             readdata = try NSString(contentsOfURL: pathname, encoding:NSUTF8StringEncoding)            as String } catch { print("read error")

}

print(readdata);

Answer

Correct Answer: read error
test data

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

136.

How to convert string into integer value? import UIKit let str_number = "320"

Answer

Correct Answer: let int1_value = Int(str_number)
let int2_value = (str_number as NSString).integerValue
let int4_value = atoi(str_number as String)

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

137.

Choose the correct answer?

import Foundation

import AVFoundation

func startCapture()

{ if let device : AVCaptureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeAudio){ do { self.session = AVCaptureSession() try device.lockForConfiguration() let audioInput = try AVCaptureDeviceInput(device: device) device.unlockForConfiguration() // audio capture operation … … } catch { } } }

Answer

Correct Answer: If AVFoundation was not imported, it will not work
If audio device was already used, this function cannot work

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

138.

Following code which is super class? class X: Y { let str:String let val:Int? … init() { … } deinit(){ … } }

Answer

Correct Answer: Y is a super class of X

Note: This Question is unanswered, help us to find answer for this one

139.

How to get local IP address in swift?

Answer

Correct Answer: getnameinfo
getIP()

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

140.

Read the following code and select output?

 import UIKit

var array:[String] = ["string1", "string2"];

 print("array list has (array.count) items.");

Answer

Correct Answer: array list has (array.count) items.

Note: This Question is unanswered, help us to find answer for this one

141.

What is the output when following statement is executed?

import UIKit

 let filename:String = "test.dat";

 let write_data:String = "write data";

 var read_data:String = "read data";

 if let directory = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.AllDomainsMask, true).first

 {

             let pathname =            NSURL(fileURLWithPath:directory).URLByAppendingPathComponent(filename);

             do {

                        try

                                    write_data.writeToURL(pathname, atomically: false, encoding: N            SUTF8StringEncoding) }

            catch { print(“write error”) }

 //reading

do

 { read_data = try NSString(contentsOfURL: pathname, encoding: NSUTF8StringEncoding) as String } catch

 { print(“read error”) } print(read_data) }

Answer

Correct Answer: write data

Note: This Question is unanswered, help us to find answer for this one

142.

The structure of a value or ____ value?

Answer

Correct Answer: struct

Note: This Question is unanswered, help us to find answer for this one

143.

How to compare below 2 strings? let str1 = "string1" let str2 = "string2”

Answer

Correct Answer: if str1 == str2

Note: This Question is unanswered, help us to find answer for this one

144.

Which of the following is safest for downcasting?

Answer

Correct Answer: as?

Note: This Question is unanswered, help us to find answer for this one

145.

If the following code executed what can be problem?

import UIKit

func MinMax(array: [Int]) -> (min: Int, max: Int)

 {

             var min = array[0];

             var max = array[0];

             for val in array[1..<array.count] {

             if val< min { min = val }

             else if val> max { max = val }

             }

             return (min, max)

}

Answer

Correct Answer: min and max variables should be defined as optional variables

Note: This Question is unanswered, help us to find answer for this one

146.

What will be the output of the following code snippet? let val1 = "Hello," let val2 = "World!" var result = val1 \ val2 print( result )

Answer

Correct Answer: Compiler Error

Note: This Question is unanswered, help us to find answer for this one

147.

A while loop performs a set of statements until a condition becomes false. These kinds of loops are best used when the number of iterations is not known before the first iteration begins. Swift provides two kinds of while loops?

Answer

Correct Answer: All of the above (1st two options are correct)

Note: This Question is unanswered, help us to find answer for this one

148.

Closure expressions in Swift language follow crisp, optimization, and lightweight syntax styles which includes?

Answer

Correct Answer: All of the them

Note: This Question is unanswered, help us to find answer for this one

149.

In Swift there are ____ kinds of types named and Compound?

Answer

Correct Answer: two

Note: This Question is unanswered, help us to find answer for this one

150.

____ in Swift is implemented with the is and as operators. These two operators provide a simple and expressive way to check the type of a value or cast a value to a different type?

Answer

Correct Answer: Type casting

Note: This Question is unanswered, help us to find answer for this one

151.

ARC tracks how many , , and variables?

Answer

Correct Answer: properties
constants

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

152.

How to connect UI in Swift Language?

Answer

Correct Answer: Same as like c-objective. There is no change in binding process only core level has been changed. You can choose button/label on xib file and binding as is it.

Note: This Question is unanswered, help us to find answer for this one

153.

How to enumerate an enum with String type, using the following code?

Answer

Correct Answer: enum Suit { case Spades, Hearts, Diamonds, Clubs func simpleDescription() -> String { switch self { case .Spades: return "spades" case .Hearts: return "hearts" case .Diamonds: return "diamonds" case .Clubs: return "clubs" } } }

Note: This Question is unanswered, help us to find answer for this one

154.

Storing Swift value types in Core Data?

Answer

Correct Answer: All of the above

Note: This Question is unanswered, help us to find answer for this one

155.

In Swift, a function is defined by the "____"?

Answer

Correct Answer: func

Note: This Question is unanswered, help us to find answer for this one

156.

Define Initializer Role for Stored Properties?

Answer

Correct Answer: All of the above

Note: This Question is unanswered, help us to find answer for this one

157.

Delegation is a design pattern that enables _____?

Answer

Correct Answer: class

Note: This Question is unanswered, help us to find answer for this one

158.

An __ defines a common type for a group of related values and enables you to work with those values in a type-safe way within your code?

Answer

Correct Answer: enumeration

Note: This Question is unanswered, help us to find answer for this one

159.

Which of the following is not a valid data type in Swift?

Answer

Correct Answer: MovieClip

Note: This Question is unanswered, help us to find answer for this one

160.

This represents a Boolean value which is either true or false?

Answer

Correct Answer: Bool

Note: This Question is unanswered, help us to find answer for this one

161.

Which keyword is used to define a constant?

Answer

Correct Answer: let

Note: This Question is unanswered, help us to find answer for this one

162.

The example below defines two variables, movieCount and songCount, which count the number of Movie and Song instances in the library array?

Answer

Correct Answer: var movieCount = 0 var songCount = 0 for item in library { if item is Movie { ++movieCount }else if item is Song { ++songCount } } println("Media library contains \(movieCount) movies and \ (songCount) songs")

Note: This Question is unanswered, help us to find answer for this one

163.

Use func to declare a function. Call a function by following its name with a list of arguments in parentheses. Use -> to separate the parameter names and types from the function’s return type?

Answer

Correct Answer: func greet(name: String, day: String) -> String { return "Hello \(name), today is \(day)." } greet("Bob", "Tuesday")

Note: This Question is unanswered, help us to find answer for this one

164.

__ can require that conforming types have specific instance properties, instance methods, type methods, operators, and subscripts?

Answer

Correct Answer: Protocols

Note: This Question is unanswered, help us to find answer for this one

165.

How do you save local storage data in a swift application?

Answer

Correct Answer: All of the above

Note: This Question is unanswered, help us to find answer for this one

166.

How to get userinfo from NSNotification in swift 3?

Answer

Correct Answer: func downloadProgress(notification:NSNotification){ if let userInfo = notification.userInfo as [String: Any] { print(userInfo) if let progressValue = userInfo["progressPercentage"] as? Float { if progressValue > 0.01{ } } } }

Note: This Question is unanswered, help us to find answer for this one

167.

Protocols can be accessed as types in?

Answer

Correct Answer: All of the above

Note: This Question is unanswered, help us to find answer for this one

168.

Swift has built-in support for checking _____ which ensures that you don’t accidentally use APIs that are unavailable on a given deployment target?

Answer

Correct Answer: API availability

Note: This Question is unanswered, help us to find answer for this one

169.

List out what are the control transfer statements used in Swift?

Answer

Correct Answer: All of the above

Note: This Question is unanswered, help us to find answer for this one

170.

Swift Generics & Upcasting

Answer

Correct Answer: class Fruit {} class Apple: Fruit {} class Orange: Fruit {} class Basket<T: Fruit> { private var items: [T] func add(item: T) { items.append(item) } init() {} } func addItem<T: Fruit>(var basket: Basket<T>, item: T) { basket.add(item) } let basket:Basket<Apple> = Basket() addItem(basket as Basket<Fruit>, Orange())

Note: This Question is unanswered, help us to find answer for this one

171.

Tuples group multiple values into a single _____ value?

Answer

Correct Answer: compound

Note: This Question is unanswered, help us to find answer for this one

172.

What is Swift ?

Answer

Correct Answer: Swift is Apple's latest programming language for iOS and OS X apps that builds on the best of C and Objective-C, without the constraints of C compatibility. Swift adopts safe programming patterns and adds modern features to make programming easier, and flexible.

Note: This Question is unanswered, help us to find answer for this one

173.

What is the difference between let and var in swift? let x = 10 var x = 10

Answer

Correct Answer: C- Both(A,B)

Note: This Question is unanswered, help us to find answer for this one

174.

How to hide status bar in ios app with Swift?

Answer

Correct Answer: We need override prefersStatusBarHidden() function on the view controller to return true always
We need set UIApplication.sharedApplication().statusBarHidden=true; with viewWillAppear() function overriding

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

175.

Which of is not a valid Access control in Swift?

Answer

Correct Answer: protected

Note: This Question is unanswered, help us to find answer for this one

176.

Initialization is the process of preparing an instance of a _____?

Answer

Correct Answer: All of the above

Note: This Question is unanswered, help us to find answer for this one

177.

Restrict extensions on a type in Swift?

Answer

Correct Answer: final class Person { private let name: String func tellName() -> String { return "I am \(name)" } init(name: String) { self.name = name } }

Note: This Question is unanswered, help us to find answer for this one

178.

Which of the following True statments of Closures?

Answer

Correct Answer: All of the above

Note: This Question is unanswered, help us to find answer for this one

179.

Shifting Behavior for Unsigned Integers?

Answer

Correct Answer: Existing bits are moved to the left or right by the requested number of places.
Any bits that are moved beyond the bounds of the integer’s storage are discarded.
Zeros are inserted in the spaces left behind after the original bits are moved to the left or right.

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

180.

What is Managing Memory in Swift?

Answer

Correct Answer: All of the above

Note: This Question is unanswered, help us to find answer for this one

181.

What will be the output of the following code snippet?

 var ary1 = [1, 2, 3, 4];

 var ary2 = ary1;

 ary2.append(5);

 var result = ary1.count;

Answer

Correct Answer: 4

Note: This Question is unanswered, help us to find answer for this one

182.

What are the features of Swift Programming?

Answer

Correct Answer: All of the above

Note: This Question is unanswered, help us to find answer for this one

183.

Which of the following could be used to indicate the Function Type of the following function: func joinStrings(stringOne: String, stringTwo: String) -> String { return stringOne + stringTwo }

Answer

Correct Answer: (String, String) -> String

Note: This Question is unanswered, help us to find answer for this one

184.

What is the output of this segment of code?
var x = 0
for index in 1...5 {
++x
}
println("\(x)")

Answer

Correct Answer: 5

Note: This Question is unanswered, help us to find answer for this one

185.

Which of the following statements about Extensions is false?

Answer

Correct Answer: Extensions can override existing functionality.

Note: This Question is unanswered, help us to find answer for this one

186.

Which one is correct function definition?

Answer

Correct Answer: funcsayHello(personName: String) -> String {}

Note: This Question is unanswered, help us to find answer for this one

187.

If a class has a superclass and conforms to multiple protocols, what is the correct order to list their names in the initial definition of the Subclass?

Answer

Correct Answer: Super class first, protocols followed by comma.

Note: This Question is unanswered, help us to find answer for this one

188.

Which of these operators is used to check whether or not two instances are identical?

Answer

Correct Answer: ==

Note: This Question is unanswered, help us to find answer for this one

189.

Which of the following could be used to loop through the range of numbers 5-12 including 12?

Answer

Correct Answer: for i in 5,i>12,i++

Note: This Question is unanswered, help us to find answer for this one

190.

With which keyword can you declare a constant in Swift?

Answer

Correct Answer: let

Note: This Question is unanswered, help us to find answer for this one

191.

To declare a function in Swift you would use what keyword?

Answer

Correct Answer: func

Note: This Question is unanswered, help us to find answer for this one

192.

In the below text, what is the property name?

class Square: NamedShape {

var sideLength: Double

 func area() -> Double {
    return sideLength * sideLength
}

}

Answer

Correct Answer: sideLength

Note: This Question is unanswered, help us to find answer for this one

193.

In the below text, what is the super class name?

class Square: NamedShape {

var sideLength: Double

func area() -> Double {
     return sideLength * sideLength
}

}

Answer

Correct Answer: NamedShape

Note: This Question is unanswered, help us to find answer for this one

194.

What is the correct way to compare the equality of two String type objects in Swift?

Answer

Correct Answer: ==

Note: This Question is unanswered, help us to find answer for this one

195.

Which is not a control transfer statement in Swift?

Answer

Correct Answer: goto

Note: This Question is unanswered, help us to find answer for this one

196.

Which keyword do you use to define a class?

Answer

Correct Answer: class

Note: This Question is unanswered, help us to find answer for this one

197.

What is a mutating instance method in Swift?

Answer

Correct Answer: When instance method without extension can modify itself.

Note: This Question is unanswered, help us to find answer for this one

198.

If we have a class named MyClass with a nested enum called Status, declared like so:

class MyClass {
    enum Status {
        case On, Off
    }
}

How would one indicate that a variable is an enum of type Status outside the context of MyClass?

Answer

Correct Answer: var status: MyClass.Status = .On

Note: This Question is unanswered, help us to find answer for this one

199.

To declare a constant in Swift you would use:

Answer

Correct Answer: let

Note: This Question is unanswered, help us to find answer for this one

200.

Can Structures be type cast in Swift?

Answer

Correct Answer: No

Note: This Question is unanswered, help us to find answer for this one

201.

What is the output of this segment of code:
var x = 0 for index in 1...5 { ++x } print("(x)")

Answer

Correct Answer: 5

Note: This Question is unanswered, help us to find answer for this one

202.

Swift can compile alongside what other language?

Answer

Correct Answer: Objective C

Note: This Question is unanswered, help us to find answer for this one

203.

Which Swift Type is used to group multiple values into a single compound value? For example:let compoundValue = (3, 5)

Answer

Correct Answer: Tuple

Note: This Question is unanswered, help us to find answer for this one

204.

What symbol is used like a tuple to access arguments in Abbreviated Swift Closure syntax?

Answer

Correct Answer: $

Note: This Question is unanswered, help us to find answer for this one

205.

What is the type of Swift Enumerations?

Answer

Correct Answer: Value type

Note: This Question is unanswered, help us to find answer for this one

206.

What is the most basic difference between Value and Reference types?

Answer

Correct Answer: Assigning a Value type to a new variable copies its contents to a new instance, where Reference types do not.

Note: This Question is unanswered, help us to find answer for this one

207.

What happens when Swifts String, Array, and Dictionary objects are assigned to a new constant or variable?

Answer

Correct Answer: They are copied.

Note: This Question is unanswered, help us to find answer for this one

208.

Which of these collection types is not included by default in standard Swift?

Answer

Correct Answer: NA

Note: This Question is unanswered, help us to find answer for this one

209.

Which of these statements declares cityArray as a mutable array?

Answer

Correct Answer: var cityArray = ["Portland","San Francisco","Cupertino"]

Note: This Question is unanswered, help us to find answer for this one

210.

Which keyword do you use to define a protocol?

Answer

Correct Answer: protocol

Note: This Question is unanswered, help us to find answer for this one

211.

How could we extend String to conform to protocol MyProtocol? Answers:

Answer

Correct Answer: extension String: MyProtocol { }

Note: This Question is unanswered, help us to find answer for this one

212.

Which of the following statements is true when talking about classes and structures in Swift?

Answer

Correct Answer: Both can be extended

Note: This Question is unanswered, help us to find answer for this one

213.

Which keyword is used to declare an extension in Swift?

Answer

Correct Answer: extension

Note: This Question is unanswered, help us to find answer for this one

214.

Which is correct for the following codes?

class Country{ let name: String init(name: String){ self.name = name; } var city: City? } class City{ let name: String init(name: String){ self.name = name; } var country: Country? } var bangladesh: Country? var khulna: City? bangladesh = Country( name: "Bangladesh" ) khulna = City( name: "Khulna" ) bangladesh?.city = khulna khulna?.country = bangladesh bangladesh = nil khulna = nil

Answer

Correct Answer: Neither Country, nor City will be deallocated.

Note: This Question is unanswered, help us to find answer for this one

215.

How can you use a nested type outside of its definition?

Answer

Correct Answer: Prefix its name with the name of the type it is nested within.

Note: This Question is unanswered, help us to find answer for this one

216.

How could we declare a custom protocol that inherits from Equatable?

Answer

Correct Answer: protocol CustomEquatable: Equatable {…}

Note: This Question is unanswered, help us to find answer for this one

217.

Why are IBOutlets declared with a weak attribute by default?

Answer

Correct Answer: IBOutlets are not declared with a weak attribute by default.

Note: This Question is unanswered, help us to find answer for this one

218.

To which of these types does ARC apply?

Answer

Correct Answer: Class

Note: This Question is unanswered, help us to find answer for this one

219.

What is true about Memory management in Swift?

Answer

Correct Answer: Swift uses ARC but we still need to avoid reference cycles using weak and strong references etc.

Note: This Question is unanswered, help us to find answer for this one

220.

How will ARC handle "Country" instance and "country2" reference when "country1" is set to "nil"?

class Country{ let name: String init(name: String){ self.name = name } } var country1: Country? var country2: Country? country1 = Country(name: "Bangladesh") country2 = country1

Answer

Correct Answer: ARC will not deallocate the Country instance and country2 will hold it’s name "Bangladesh"

Note: This Question is unanswered, help us to find answer for this one

221.

What will be the final value of "a.data" and "b.data" after following codes are executed?

struct A { var data: Int = 2 } var a = A() var b = a var c = b c.data = 10 a.data = 5

Answer

Correct Answer: a.data = 5 and b.data = 2

Note: This Question is unanswered, help us to find answer for this one

222.

What is the type of Swift String, Dictionary, Array?

Answer

Correct Answer: Class

Note: This Question is unanswered, help us to find answer for this one

223.

Which keyword do you use to define a function?

Answer

Correct Answer: func

Note: This Question is unanswered, help us to find answer for this one

224.

What is the name of the following function: func potteryBarn (name: String, score: Int) -> String { return "Hello (name)! Your score is (score)." }

Answer

Correct Answer: potteryBarn

Note: This Question is unanswered, help us to find answer for this one

225.

AnyObject can represent:

Answer

Correct Answer: an instance of any class type.

Note: This Question is unanswered, help us to find answer for this one

226.

Which of these is an invalid constant or variable declaration?

Answer

Correct Answer: let = 3.14159

Note: This Question is unanswered, help us to find answer for this one

227.

To loop through a range of the numbers 1-9 without using 9, you would write…

Answer

Correct Answer: for i in 1..<9

Note: This Question is unanswered, help us to find answer for this one

228.

Which is the correct optional form of a down cast operator?

Answer

Correct Answer: as?

Note: This Question is unanswered, help us to find answer for this one

229.

What are the names of the input parameters in the following function: func potteryBarn (name: String, score: Int) -> String {return "Hello (name)! Your score is (score)."}

Answer

Correct Answer: name, score

Note: This Question is unanswered, help us to find answer for this one

230.

What is the return type in the following declaration: func potteryBarn (name: String, score: Int) -> String { return "Hello (name)! Your score is (score)." }

Answer

Correct Answer: String

Note: This Question is unanswered, help us to find answer for this one

231.

What is the result of the following code? func potteryBarn (name: String, score: Int) -> String { return "Hello (name)! Your score is (score)." } potteryBarn ("Tom" , 2)

Answer

Correct Answer: Hello Tom! Your score is 2.

Note: This Question is unanswered, help us to find answer for this one

232.

When declaring a function, what symbol is used to indicate that an internal parameter name should also be used as an external parameter?

Answer

Correct Answer: _ (right answer)

Note: This Question is unanswered, help us to find answer for this one

233.

In what order will the following statements appear in the console? println("1") dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY _DEFAULT, 0), {println("2")}); println("3")

Answer

Correct Answer: 1/3/2

Note: This Question is unanswered, help us to find answer for this one

234.

In what queue should all UI code be handled?

Answer

Correct Answer: MainQueue

Note: This Question is unanswered, help us to find answer for this one

235.

Which of the following is correct to cube Integer?

Answer

Correct Answer: extension Int { mutating func cube () { self = selfselfself } }

Note: This Question is unanswered, help us to find answer for this one

236.

What will happen if you assign a value to a property within its own didSet observer?

Answer

Correct Answer: The property will take on that value

Note: This Question is unanswered, help us to find answer for this one

237.

Which of following expressions can be used to rewrite the following UITableView instantiation in Swift UITableView *myTableView = [[UITableView alloc] initWithFrame: CGRectZero style: UITableViewStyleGrouped];

Answer

Correct Answer: let myTableView: UITableView = UITableView(frame: CGRectZero, style: .Grouped);

Note: This Question is unanswered, help us to find answer for this one

238.

What aspect of iOS development requires the use of NSOperation and/or Grand Central Dispatch (GCD)?

Answer

Correct Answer: Multithreading

Note: This Question is unanswered, help us to find answer for this one

239.

  In the below text, what is the name of the class’s only method? Class Square: NamedShape { var sideLength: Double func area() -> Double { return sideLength*sideLength } }

Answer

Correct Answer: area

Note: This Question is unanswered, help us to find answer for this one

240.

In the below text, what is the class name? Class Square: NamedShape { var sideLength: Double func area() -> Double { return sideLength*sideLength } }

Answer

Correct Answer: Square

Note: This Question is unanswered, help us to find answer for this one

241.

  In the below text, what type of return does the function ‘area’ give? Class Square: NamedShape { var sideLength: Double func area() -> Double { return sideLength*sideLength } }

Answer

Correct Answer: Double

Note: This Question is unanswered, help us to find answer for this one

242.

Which of following statements about functions is wrong?

Answer

Correct Answer: In-out parameters might have a default value

Note: This Question is unanswered, help us to find answer for this one

243.

What specifies custom infix operator?

Answer

Correct Answer: it is a binary operator, taking a left and right hand argument

Note: This Question is unanswered, help us to find answer for this one

244.

What are the available arithmetic overflow operators in Swift?

Answer

Correct Answer: &+,&-,&*,&/,&%

Note: This Question is unanswered, help us to find answer for this one

245.

Which of the following statements is true regarding Swift closures and functions?

Answer

Correct Answer: A Function is a named Closure

Note: This Question is unanswered, help us to find answer for this one

246.

What is a trailing closure?

Answer

Correct Answer: A closure expression that is written outside of (and after) the parentheses of the function call it supports.

Note: This Question is unanswered, help us to find answer for this one

247.

How could the following closure be rewritten to use shorthand arguments? s2 } ) >

Answer

Correct Answer: reversed = sorted(names, { $0 > $1 } )

Note: This Question is unanswered, help us to find answer for this one

248.

How could you call the following function that takes a closure as an argument using trailing closure syntax: ()) { // function body goes here }>

Answer

Correct Answer: funcWithClosure() { //closure’s body goes here }

Note: This Question is unanswered, help us to find answer for this one

249.

Let’s assume "numbers" is an array of unsorted integers. Which of these could be used to sort numbers?

Answer

Correct Answer: numbers.sort({$0 > $1})

Note: This Question is unanswered, help us to find answer for this one

250.

Choose the answer that declares an optional closure.

Answer

Correct Answer: var closureName: ((parameterTypes) -> (returnType))

Note: This Question is unanswered, help us to find answer for this one

251.

How can we use optional binding to determine if the variable string is not nil?

Answer

Correct Answer: if let str = string {…}

Note: This Question is unanswered, help us to find answer for this one

252.

What set of keywords is most commonly used to iterate over a collections of items?

Answer

Correct Answer: for in

Note: This Question is unanswered, help us to find answer for this one

253.

How could we cast the following array into an NSArray that accesses the NSArray method:
componentsJoinedByString() < let arr = ["1", "2", "3"]

Answer

Correct Answer: (arr as NSArray).componentsJoinedByString(",")

Note: This Question is unanswered, help us to find answer for this one

254.

How could one declare a Swift Array type that can store any type of class object?

Answer

Correct Answer: var arr: [AnyObject] = [ ]

Note: This Question is unanswered, help us to find answer for this one

255.

Which is correct regarding optional form of the type cast operator (as?)?

Answer

Correct Answer: Return value will be nil if the downcast was not possible

Note: This Question is unanswered, help us to find answer for this one

256.

How could we create a subclass of the Structure, CGRect?

Answer

Correct Answer: You can not subclass a Structure

Note: This Question is unanswered, help us to find answer for this one

257.

Considering the following code, which statement is Correct:
let array1 = ["A", "B", "C"] var array2 = array1 array2.append("D")

Answer

Correct Answer: Reference count of array1 won't change after the assignment

Note: This Question is unanswered, help us to find answer for this one

258.

Swift Extensions are similar to categories in Objective-C except:

Answer

Correct Answer: Swift extensions are not named.

Note: This Question is unanswered, help us to find answer for this one

259.

What is a muting instance method in Swift?

Answer

Correct Answer: When instance method without extension can modify itself.

Note: This Question is unanswered, help us to find answer for this one

260.

What is the type name that represents a character in Swift?

Answer

Correct Answer: Character

Note: This Question is unanswered, help us to find answer for this one

261.

What is the name of the Objective-C Bridging Header given a product module named Example?

Answer

Correct Answer: Example-Bridging-Header.h

Note: This Question is unanswered, help us to find answer for this one

262.

What is used in Swift to represent any kind of object?

Answer

Correct Answer: AnyObject

Note: This Question is unanswered, help us to find answer for this one

263.

How do closures capture references to variables by default ?

Answer

Correct Answer: By strong reference

Note: This Question is unanswered, help us to find answer for this one

264.

When declaring an enumeration, multiple member values can appear on a single line, separated by which punctuation mark?

Answer

Correct Answer: Comma

Note: This Question is unanswered, help us to find answer for this one

265.

Which keyword do you use to declare enumeration?

Answer

Correct Answer: enum

Note: This Question is unanswered, help us to find answer for this one

266.

Which of the following types can be used use as raw value types for an enumeration?

Answer

Correct Answer: Int, String, Float

Note: This Question is unanswered, help us to find answer for this one

267.

Which is used for down casting?

Answer

Correct Answer: as!
as?

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

268.

Which keyword is used in Swift when we want a property of a class to initialize when it is accessed for the first time?

Answer

Correct Answer: lazy

Note: This Question is unanswered, help us to find answer for this one

269.

Which of the following declares a mutable array in Swift?

Answer

Correct Answer: var x = [Int]()

Note: This Question is unanswered, help us to find answer for this one

270.

Can enumeration type have methods?

Answer

Correct Answer: Enumerations can have methods associate with them.

Note: This Question is unanswered, help us to find answer for this one

271.

Given that we have defined myChar like so :
let myChar: Character = "b" Which code segment can be considered a complete Switch statement and will run without any error?

Answer

Correct Answer: switch myChar { case "a","A": println("The letter A") default: println("Not the letter A") }

Note: This Question is unanswered, help us to find answer for this one

272.

What type of object are Swift Structures?

Answer

Correct Answer: Value Type

Note: This Question is unanswered, help us to find answer for this one

273.

Which is correct regarding Swift enumeration members when they are defined?

Answer

Correct Answer: Members are not assigned default integer values.

Note: This Question is unanswered, help us to find answer for this one

274.

What keyword is used to indicate a custom operator that will appear in between two targets, similar to the addition operator in this example?
var sum = 10 + 10

Answer

Correct Answer: infix

Note: This Question is unanswered, help us to find answer for this one

275.

What is used to import Objective-C files into Swift?

Answer

Correct Answer: Objective-C classes are imported via a Bridging Header.

Note: This Question is unanswered, help us to find answer for this one

276.

In context of a Swift subscript, which of the following is correct?

Answer

Correct Answer: struct MyStruct { var myStr = [String]() subscript (index : Int) -&gt; String{ get{ return myStr[index] } set{ myStr[index] = newValue } } }

Note: This Question is unanswered, help us to find answer for this one

277.

Which of these could be an appropriate protocol declaration in Swift?

Answer

Correct Answer: @objc protocol someProtocal { optional var first: Int { get } }

Note: This Question is unanswered, help us to find answer for this one

278.

Which of the following statements could be used to determine if a given variable is of String type?

Answer

Correct Answer: if unknownVariable is String { }

Note: This Question is unanswered, help us to find answer for this one

279.

Which of these is a valid definition of a generic function that incorporates inout parameters in Swift?

Answer

Correct Answer: func swap&lt;T&gt;(inout a: T, inout b: T) { let temp = a a = b b = temp }

Note: This Question is unanswered, help us to find answer for this one

280.

Which keyword is used on a function inside an Enumeration to indicate that the function will modify 'self'?

Answer

Correct Answer: mutating

Note: This Question is unanswered, help us to find answer for this one

281.

All Swift classes must inherit from which root class?

Answer

Correct Answer: Swift classes do not require a root class.

Note: This Question is unanswered, help us to find answer for this one

282.

Which of the following structures has both computed and stored properties?

Answer

Correct Answer: struct Rect { var origin = CGPointZero var center: CGPoint { get { // } set { // } } }

Note: This Question is unanswered, help us to find answer for this one

283.

Which is the wrong definition of a protocol in Swift?

Answer

Correct Answer: protocol SomeProtocol { var first: Int{ set } }

Note: This Question is unanswered, help us to find answer for this one

284.

Which of these is not a valid property declaration in Swift?

Answer

Correct Answer: final lazy let x = 0

Note: This Question is unanswered, help us to find answer for this one

285.

Which of these is an appropriate syntax for declaring a function that takes an argument of a generic type?

Answer

Correct Answer: func genericFunction<T>(argument: T) { }

Note: This Question is unanswered, help us to find answer for this one

286.

What is the name of the deinitializer in a Class declaration?

Answer

Correct Answer: deinit

Note: This Question is unanswered, help us to find answer for this one

287.

Which of these is an appropriate syntax for dispatching a heavy operation to a background thread?

Answer

Correct Answer: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIO RITY_BACKGROUND, 0), { self.heavyOperation() })

Note: This Question is unanswered, help us to find answer for this one

288.

Which one creates a dictionary with a key type of Integer and value of String?

Answer

Correct Answer: var dict: [Int: String] = [1:"one"]

Note: This Question is unanswered, help us to find answer for this one

289.

What is the name of the Swift language feature that Objective-C Blocks are translated into?

Answer

Correct Answer: Closure

Note: This Question is unanswered, help us to find answer for this one

290.

Which of these is a valid syntax for iterating through the keys and values of a dictionary?
let dictionary = [keyOne : valueOne, keyTwo : valueTwo]

Answer

Correct Answer: for (key, value) in dictionary { println("Key: (key) Value: (value)") }
for (key, value) in dictionary.enumerate() { println("Key: (key) Value: (value)") }

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

291.

Which one of the below functions definitions is wrong considering Swift language?

Answer

Correct Answer: func haveChar(#string: String, character: Character) -> (Bool)

Note: This Question is unanswered, help us to find answer for this one

292.

What does a retainCount represent in ARC?

Answer

Correct Answer: The current number of strong references to an object.

Note: This Question is unanswered, help us to find answer for this one

293.

What is the name of the Xcode generated header file used to import Swift classes into an Objective-C Class given a product module named Example?

Answer

Correct Answer: Example-Swift.h

Note: This Question is unanswered, help us to find answer for this one

294. In Apple Swift, which of the following operators cannot be overloaded?

Answer

Correct Answer: Assignment operator (=)
Ternary conditional operator (?:)

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

295. In Apple Swift, which of the following options hold true?

Answer

Correct Answer: 8% 2 returns 0
23 % 7.5 returns 0.5

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

296. In Apple Swift, which of the following statements are correct regarding protocols?

Answer

Correct Answer: They can be used as a return type in a function.
They can be used as the type of items in a dictionary.

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

297. Which of the following statements are correct about properties in the Apple Swift language?

Answer

Correct Answer: An Apple Swift property does not have a corresponding instance variable.
Computed properties can be def‌ined by enumerations in the Apple Swift language.

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

298. ln Apple Swift. which of the following operators are right-associative?

Answer

Correct Answer: ?:
??

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

299. In Apple Swift, which of the following variables and constants are computed lazily?

Answer

Correct Answer: Global constants
Global variables

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

300. In Apple Swift, which of the following statements are incorrect regarding structures?

Answer

Correct Answer: Methods can be def‌ined by structures to provide functionality.
Reference counting permits more than one reference to a structure instance.

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

301. Which of the following statements are incorrect regarding a deinitializer in Apple Swift?

Answer

Correct Answer: There can be at most two deinitializers per class.
A deinitializer always takes one parameter.

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

302. In Apple Swift, which of the following statements are correct about extensions?

Answer

Correct Answer: They can def‌ine type methods.
They can add computed properties.

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

303. In Apple Swift, if an optional variable is defined without providing an initial value, then that particular variable is automatically set to which of the following?

Answer

Correct Answer: nil

Note: This Question is unanswered, help us to find answer for this one

304. Which of the following access levels is NOT provided by Apple Swift?

Answer

Correct Answer: Protected access

Note: This Question is unanswered, help us to find answer for this one

305. In Apple Swift, subscripts can take:

Answer

Correct Answer: any number of parameters.

Note: This Question is unanswered, help us to find answer for this one

306.

Based on your analysis of the above code. find out the output generated by the following lines.

let b1 = abc([9,-7,3,110,4,721)

print("number: \(b1.x), \(b1.y)")


Answer

Correct Answer:

number: -21, 330  


Note: This Question is unanswered, help us to find answer for this one

307. In Swift, which of the following collection types is/are implemented as (a) generic collection(s)? 0 Array

Answer

Correct Answer: Both a and b

Note: This Question is unanswered, help us to find answer for this one

308.

What will be the output of the following code?

class a1 {

func cn10

{

for var a = 9; a >=1; --a {

for var b = 9; b >= 0; --b{

if b%2==a/2 [

print((b%4),terminator: "“)

}

}

print("")

}}}

lets = a1()

s.cn1()

Answer

Correct Answer:

13131

13131

02020



Note: This Question is unanswered, help us to find answer for this one

309.

What will be the output of the given Apple Swift code?

var nm = 5.0

class abc[

var x = 0.0

var y: String [

return "\(nm)"

]

func kp0[

println("\(n m)")

1}

let s=abc()

println(s.kp0)

class sd1: abc[

var hB = false

func k1(){

let i = abc();

println("\(i.y)")

let be = sd1()

bc.hB = true

println("\(bc.y)")

println(i.kp())

]}

class Tn: abc[

var nm=15.0

override func kp0[

println(15.0)

]}

let tr = Tn0

tr.kp0


Answer

Correct Answer:

5.0

15.0



Note: This Question is unanswered, help us to find answer for this one

310. In Apple Swift, a class:

Answer

Correct Answer: must have at least one designated initializer.

Note: This Question is unanswered, help us to find answer for this one

311. In Apple Swift, which of the following symbols is used to write an implicitly unwrapped optional?

Answer

Correct Answer: !

Note: This Question is unanswered, help us to find answer for this one

312. ln Apple Swift, which of the following references should be used when it is known that the reference will never be nil during its lifetime?

Answer

Correct Answer: Unowned references

Note: This Question is unanswered, help us to find answer for this one

313.

What will be the output of the following Apple Swift code?

enum Abc [

case Mark

case John

case Andrew

case Lucy

case June

case Kate

]

enum Class [

case First. Second. Third. Fourth. Fifth. Sixth. Seventh

1

var n1 = Abc.Lucy

n1 = .John

print(n1)

let sp = Class.Sixth

sp = .Third

switch sp {

case .Third:

print("Perrnitted to the cricket ground")

default:

print("Not Permitted to the cricket ground")

]


Answer

Correct Answer:

Code will give compilation error.  


Note: This Question is unanswered, help us to find answer for this one

314. In Apple Swift, if we dont want to provide an external name for the second parameter of a method, then which of the following symbols can be used to override the default behavior?

Answer

Correct Answer: _ (Underscore)

Note: This Question is unanswered, help us to find answer for this one

315.

Based on your analysis of the following Apple Swift code, identify from the given options the code that will generate compilation error when executed.

func abc(inout a: T, inout _ b: T) {

let a1 = a

a = b

b = a1

print("\(a) \(b)")

}


Answer

Correct Answer:

var z =

Note: This Question is unanswered, help us to find answer for this one

316.

Analyze the following Apple Swift code and select its correct output from the given options.

struct a1 [

var x = 0.0, y = 0.0

}

struct b1 {

var w = 0.0. h = 0.0

}

struct Rt{

var n1 = a1()

var 51 = b1()

var c1: a1 {

getl

let cX = n1.x + (sI.w / 2)

let CY = n1.y -|- (s1.h / 2)

return a1(x: cX. y: cY)

}

set(cc) [

n1.x = cc.x - (s1.w ‘36 4)+2.5

n1.y = my - (sl.h % 4)+2.5

I I I

var rr = Rt(n1: a1(x: 0.0, y: 0.0),

$1: b1(w: 10.0, h: 10.0))

let isc = rr.c1

rr.c1 = a1(x: 16.0, y: 16.0)

print("\(rr.n1.x), \(rr.n1.y)")


Answer

Correct Answer:

16.5.16.5


Note: This Question is unanswered, help us to find answer for this one

317.

What will be the output of the last line of the given Apple Swift code?

let a=4

print(a&+0)

print(a&-O)

print(a&0)

print(a<<1)

print(a>>1)

print(a<<2)


Answer

Correct Answer:

16


Note: This Question is unanswered, help us to find answer for this one

318.

Analyze the Apple Swift code given in Image 1, and choose its correct output from Image

Answer

Correct Answer: (i)
(ii)

Note: This question has more than 1 correct answers

Note: This Question is unanswered, help us to find answer for this one

319.

Which of the following statements are valid regarding an assignment operator in Apple Swift?

1. let b=10

2. let (a,b) = (2, 3)

3. if a = b { )


Answer

Correct Answer:

Only1 and 2


Note: This Question is unanswered, help us to find answer for this one

320. In Apple Swift, which type of parameters cannot be used by subscripts?

Answer

Correct Answer: In-out parameters

Note: This Question is unanswered, help us to find answer for this one

321.

What will be the output of the following code?

class 81 (

func cn10

l

for var a = 9; a >= 1; --a[

for var b = 9; b >= 0; --b[

if b%2==a/2 [

print((b%4).terminator: "")

I

I

print("")

III

let s = a10

s.cn10


Answer

Correct Answer:

13131

13131

02020  



Note: This Question is unanswered, help us to find answer for this one

322.

Choose True or False.

In Apple Swift, structures are reference types, whereas classes are value types.


Answer

Correct Answer:

False 


Note: This Question is unanswered, help us to find answer for this one

323.

How many times will the following Apple Swift code print the word "green"?

for p in 21...34[

if p%2==1[

var a = "red"

var b: String?

var c = b ?? a

print( c)

}

else if p%3==2{

let a = "green"

let e = "red"

var f = e ?? a

print(f)

}

else(

var g = "green"

var h: String?

var k = h ?? g

print(k)

}

}


Answer

Correct Answer:

5


Note: This Question is unanswered, help us to find answer for this one

324.

What will be the output of the following code?

func abc(p: Double...) -> Double {

var sm: Double = O

for number in p[

sm += number

I

return sm I Double{p.count)

I

print(abc(6, 7.25, 16.75))


Answer

Correct Answer:

10.0


Note: This Question is unanswered, help us to find answer for this one

325.

What will be the output of the following Apple Swift code?

func abc(param1: String) -> lnt[

print(param1)

return param1.characters.count

}

func xyz(param1: String) [

abc(paramI)

}

xyz.("John Smith")


Answer

Correct Answer:

10


Note: This Question is unanswered, help us to find answer for this one

326. In Apple Swift, which of the following is the correct "identical to" operator?

Answer

Correct Answer: ===

Note: This Question is unanswered, help us to find answer for this one

327. In Apple Swift, which of the following statements is incorrect regarding inheritance?

Answer

Correct Answer: All the classes in Apple Swift are inherited from a universal base class.

Note: This Question is unanswered, help us to find answer for this one

328.

What will be the output of the given Apple Swift code?

let a;zUlnt8 = 0b11101111

let sz;lnt8 = 0b00110011

let c=a&b

print(c)


Answer

Correct Answer:

35


Note: This Question is unanswered, help us to find answer for this one

329.

In Apple Swift, which of the given statements is correct about initializers?

1. Failable and non-failable initializers can be def‌ined with the same name and parameter types

2. No value can be returned by initializers.

3. A failable initializer cannot delegate to a non-failable initializer.


Answer

Correct Answer:

Only 2


Note: This Question is unanswered, help us to find answer for this one

330. Which of the following options holds true for observers in Apple Swift, when a property is set in an initializer before delegation takes place?

Answer

Correct Answer: Neither willset nor didset observer is called.

Note: This Question is unanswered, help us to find answer for this one

331.

In Apple Swift, which of the following parameters can be used in a closure expression?

1. Constant parameters

2. Variable parameters

3. Inout parameters

4. Variadic parameters

5. Tuple parameters


Answer

Correct Answer:

All of the given parameters can be used in a closure expression.


Note: This Question is unanswered, help us to find answer for this one

332.

Which of the following statements are incorrect regarding closures in Apple Swift?

1. In Apple Swift, a closure can capture all the references to variables from the surrounding context in which it is def‌ined, but cannot capture references to constants.

2. A nested function is a closure that has a name but it cannot capture any value from its enclosing function.

3. A global function is a closure that has a name and does not capture any value.


Answer

Correct Answer:

Only1 and 2 


Note: This Question is unanswered, help us to find answer for this one