Swift quiz questions

Swift interview questions

  • 1.

    What output will be produced by the code below?

    var motto = "Bow ties are cool"
    motto.replacingOccurrences(of: "Bow", with: "Neck")
    print(motto)
    1. "Bow ties are cool"

    2. Not compile

    Answer
  • 2.

    When this code is executed, what value will num have?

    let num = UInt.min
    1. 16,777,216

    2. 0

    3. A random interger

    Answer
  • 3.

    When this code finishes executing, how many strings will the names array contain?

    let names = [String]()
    names.append("Amy")
    names.append("Clara")
    names.append("Rory")
    1. 1

    2. 2

    3. 3

    4. This code will not compile

    Answer
  • 4.

    What output will be produced by the code below?

    import Foundation
    let number = 16.0
    print("\(number) squared is \(number * number), and its square root is \(sqrt(number))")
    1. "16 squared is 16 * 16, and its square root is sqrt(16)"

    2. "16.0 squared is 256.0, and its square root is 4.0"

    3. Not compile

    Answer
  • 5.

    What output will be produced by the code below?

    class Starship {
        var type: String
        var age: Int
    }
    let serenity = Starship(type: "Firefly", age: 24)
    print(serenity.type)
    1. "Firefly"

    2. This code will not compile

    Answer
  • 6.

    What output will be produced by the code below?

    let names = ["Amy", "Clara"]
    for i in 0 ... names.length {
        print("Hello, \(names[i])!")
    }
    1. "Hello, Amy!"

    2. This code will not compile

    Answer
  • 7.

    What output will be produced by the code below?

    final class Dog {
        func bark() {
            print("Woof!")
        }
    }
    class Corgi : Dog {
        override func bark() {
            print("Yip!")
        }
    }
    let muttface = Corgi()
    muttface.bark()
    1. "Woof!", "Yip!"

    2. This code will not compile

    Answer
  • 8.

    What output will be produced by the code below?

    var i = 2
    do {
        print(i)
        i *= 2
    } while (i < 128)
    1. 2, 4, 8, 16, 32, 64

    2. This code will not compile

    Answer
  • 9.

    How many bits are used to store an Int?

    1. 32-bit

    2. 64-bit

    3. It depends on the device

    Answer
  • 10.

    What output will be produced by the code below?

    func sayHello(to name: String) -> String {
        return "Howdy, \(name)!"
    }
    print("\(sayHello(to: "Jayne"))")
    1. "Howdy!"

    2. "Howdy, Jayne!"

    3. "Hello, Jayne!"

    Answer
  • 11.

    What output will be produced by the code below?

    struct Spaceship {
        var name: String {
            willSet {
                print("I'm called \(newValue)!")
            }
        }
    }
    var serenity = Spaceship(name: "Serenity")
    serenity.name = "TARDIS"
    1. "I'm called Serenity!"

    2. "I'm called TARDIS!"

    Answer
  • 12.

    What output will be produced by the code below?

    let oneMillion = 1_000_000
    let oneThousand = oneMillion / 0_1_0_0_0
    print(oneThousand)
    1. 1000000

    2. 10000

    3. 1000

    Answer
  • 13.

    What output will be produced by the code below?

    import Foundation
    let number = 16
    print("\(number) squared is \(number * number), and its square root is \(sqrt(number))")
    1. 16 squared is 256, and its square root is 4

    2. Not compile

    Answer
  • 14.

    What output will be produced by the code below?

    let names = ["Serenity", "Sulaco", "Enterprise", "Galactica"]
    if let last = names.last {
        print(last)
    }
    1. "Galactica"

    2. "Serenity"

    3. "Enterprise"

    4. "Sulaco"

    Answer
  • 15.

    When this code is executed, what will be the value of the j constant?

    1. "5", "5"

    2. "55"

    3. Fail to compile

    Answer
  • 16.

    When this code is executed, what is the value of the swift string?

    import Foundation
    let ns = NSString("Hello")
    let swift = String(ns)
    1. Hello

    2. This code will not compile.

    3. Complie but not run

    Answer
  • 17.

    When this code is executed, what will the third constant contain?

    let first = ["Sulaco", "Nostromo"]
    let second = ["X-Wing", "TIE Fighter"]
    let third = first + second
    1. "Sulaco", "Nostromo"

    2. "Sulaco", "Nostromo", "X-Wing", "TIE Fighter"

    3. "Nostromo", "X-Wing", "TIE Fighter"

    4. "X-Wing", "TIE Fighter"

    Answer
  • 18.

    Given the code below, what data type does i have?

    let i = 10.2
    1. Double

    2. String

    3. Decimal

    4. Number

    Answer
  • 19.

    What output will be produced by the code below?

    for i in 1...3 {
        print(i)
    }
    1. 1,2

    2. 1, 2, 3

    3. 1,2,3,4

    Answer
  • 20.

    What output will be produced by the code below?

    let names = ["Serenity", "Sulaco", "Enterprise", "Galactica"]
    for name in names where name.hasPrefix("S") {
        print(name)
    }
    1. "Serenity"

    2. "Serenity", "Sulaco"

    3. "Serenity", "Sulaco", "Enterprise"

    4. "Sulaco"

    5. Nothing will be output

    6. This code will not compile

    Answer

© 2017 QuizBucket.org