Swift MCQ Question
Swift MCQ Question
Swift MCQ Question
3. a. To submit your App to the App Store you must build your app using
the version of Swift that comes included within Xcode.
b. Playgrounds are supported for downloadable Swift packages
separately on Ubuntu platform.
Only a is right.
Only b is right.
Swift code file does not need separate files for declaring interface
and implementation of class.
True False
True False
True False
True False
True False
True False
g. XCPlayground framework is required to add UIView and
UIViewController in Playground code.
True False
True False
i. Adding the first page to a playground will show two new pages.
One is the current content of the playground editor and the other
is the new page.
True False
True False
3. var name : String? = "CodingBull"
name = name + 10
Only a is right.
Only b is right.
let array = [Int]()
var array = [Int]()
let array = [Int]
var array = [Int]
Structure
Enumeration
Variables
final var x = 0
Short cut literal for creating empty Array and Dictionary both, is
same and it is [ ].
It is 32 bits.
It is 64 bits.
Int is not a valid keyword but it should be either Int8, Int16, Int32
or Int64.
11. Which Swift Type is used to group multiple values into a single
compound value? For example:
let compoundValue = (3, 5)
GroupObject
Tuple
Ordered
Struct
if String.hierarchy(unknownVariable) { }
if (String)unknownVariable { }
13. What would be used for safe casting and to return nil if failed?
as?
as!
!as?
!as!
14. Which one is the correct keyword for defining a constant in
contant
final
let
def
var a = 12
if a >= 12
print("Good after noon")
else
print("Good Morning!")
Good Morning!
Compiler error
12
var fullUrl = 1
if (fullUrl) {
print("http://www.codingbull.com")
} else {
print("codingbull.com")
}
http://www.codingbull.com
codingbull.com
Compiler error
Runtime crash
for each
switch case
repeat while
for in
goto
fallthrough
break
return
continue
5. Which keyword in the context of a Switch statement is required to
force the execution of a subsequent case?
fallthrough
continue
break
return
for i in 512
for i in 5,i>12,i++
for i in 5..<12
for i in 4..<12
for i in 0…8
for i in 0>..9
for i in 1<..8
for i in 1..<9
10,9,8,7,6,5,4,3,2,1,
10,9,8,7,6,5,4,3,2,1
10, 9, 8, 7, 6, 5, 4, 3, 2, 1,
10, 9, 8, 7, 6, 5, 4, 3, 2, 1
==
=
equalsTo
===
identicalTo
Fallthrough
Continue
Release
DropEnd
11. Which of these is a valid syntax for iterating through the keys
and values of a dictionary:
var x = 0
for index in 1...5 {
++x
}
println("\(x)")
0
compile error
5
4
function
func
@function
2. a. func printName(name: String!) -> Void{ }
b. function printName(name: String) { }
a is incorrect.
b is incorrect.
Both a & b are incorrect.
Only a is right.
Only b is right.
4. A function that has a defined return type must always return a value
because :
it won't allow control to fall out of the bottom of the function
without returning a value, and attempting to do so will result in a
compile-time error.
True
False.
10
30
Runtime crash
func mean(numbers: Double...) -> Double { }
_ [underscore]
@ [at]
: [colon]
# [hash]
Function names might be the same with another but at least one
parameter should be different
stuct
class
Class
interface
@class
2. Which root class, swift classes required to inherit from ?
Not required
NSObject
NSRootObject
Object
dealloc
release
finalize
deinit
let
var
const
lazy
Struct
structure
@struct
modifier
mutating
mutable
mod
mut
Select all right code-snippets which could be used to use the above
defined structure (SomeStruct).
var s1 = someStruct(10)
var s1 = someStruct(a: 10)
var s1: someStruct = someStruct(10)
var s1 = someStruct()
s2.a = 10
Reference Type
Memory Type
Abstract Type
Value Type
10. Few question are based on the class definition written below:
class Square: NamedShape {
var sideLength: Double
func area() -> Double {
return sideLength*sideLength
}
}
a. The name of the class's only method is __.
NamedShape
Square
area
Double
sideLength
Int
Double
area
NamedShape
Square
Double
sideLength
d. In the bellow text, what is the super class name?
Square
NamedShape
Double
area
struct CGRect(MyRect) {}
12. 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
Yes
No
enum
enumeration
Enum
NSEnum
; [Semi-colon]
: [Colon]
, [Comma]
? [Question mark]
func genericFunc(argument) { }
generic func genericFunc(argument: T) { }
func genericFunc(argument: T) { }
func(String, String -> String)
(String, String) -> String
{String, String} -> String
{String, String}(String)
6. How do closures capture references to variables by default?
By copy.
modifier
mutating
mutable
mod
mut
class MyClass {
enum Status {
case On, Off
}
}
10. Which one of the following types can be used as raw value types
for an enumeration?
Bool
Array
Dictionary
$
*
&
@
~
17. How could you call the following function that takes a closure as
an argument using trailing closure syntax:
()) { // function body goes here }>
< funcWithClosure ({
//closure’s body goes here
})>
<func funcWithClosure ({
//closure’s body goes here
})>
< funcWithClosure() {
//closure’s body goes here
}>
< funcWithClosure {
//closure’s body goes here
)>
18. What is the name of the Swift language feature that Objective-C
Blocks are translated into?
Lambda
Callback
Closure
Blocks
protocol
@interface
@protocol
Protocol
Reference type
Class type
Collection type
Value type
@inter
between
infix
@center
5. To which of these type does ARC apply?
Class
Structure
Enumeration
By copy.
modifier
mutating
mutable
mod
mut