Skip to content

Swift MCQ Questions

0
Answered
0
Correct
0%
Accuracy
Q1 Easy

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

Q2 Easy

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

Q3 Easy

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)

Q4 Easy

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

Q5 Easy

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

Q6 Easy

What is true about Memory management in Swift?

Q7 Easy

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

Q8 Easy

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

Q9 Easy

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

Q10 Easy

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

Q11 Easy

Which is the wrong definition of a protocol in Swift?

Q12 Easy

Which one is correct function definition?

Q13 Easy

What is a trailing closure?

Q14 Easy

What is Swift ?

Q15 Easy

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

Q16 Easy

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

Q17 Easy

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

Q18 Easy

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

Q19 Easy

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

Q20 Easy

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

Q21 Easy

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

Q22 Easy

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

Q23 Easy

What is Managing Memory in Swift?

Q24 Easy

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

Q25 Easy

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

Q26 Easy

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

Q27 Easy

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

Q28 Easy

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

Q29 Easy

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

Q30 Easy

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

Q31 Easy

What is the need for having structures?

Q32 Easy

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

Q33 Easy

____ 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?

Q34 Easy

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

Q35 Easy

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?

Q36 Easy

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

Q37 Easy

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

Q38 Easy

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

Q39 Easy

What is the output when following statement is executed?import UIKitlet 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 {trywrite_data.writeToURL(pathname, atomically: false, encoding: N SUTF8StringEncoding) }catch { print(“write error”) }//readingdo{ read_data = try NSString(contentsOfURL: pathname, encoding: NSUTF8StringEncoding) as String } catch{ print(“read error”) } print(read_data) }

Q40 Easy

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

Q41 Easy

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

Q42 Easy

extension Int {subscript(var myInt: Int) -> Int {var no1 = 1while myInt > 0 {no1 *= 10--myInt}return (self / no1) % 10}}print(12[0])What is the output?

Q43 Easy

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

Q44 Easy

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

Q45 Easy

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

Q46 Easy

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) } }

Q47 Easy

What is a muting instance method in Swift?

Q48 Easy

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

Q49 Easy

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

Q50 Easy

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

Showing 50 of 67 questions

Report a mistake

What's wrong?