Online Exam Quiz

questionQuestion  1 to 30

Which of the following is a valid Swift string literal?

  • "Hello"
  • Hello
  • "Hello
  • "Hello"
Mark for review

How do you access a property of a class instance in Swift?

  • instance.property
  • class.property
  • object.property
  • self.property
Mark for review

What keyword is used for inheritance in Swift?

  • extend
  • inherits
  • superclass
  • :
Mark for review

What keyword is used to handle optional values in Swift?

  • optional
  • unwrap
  • nil-coalescing
  • force-unwrap
Mark for review

How do you define a protocol in Swift?

  • protocol MyProtocol { }
  • define protocol MyProtocol { }
  • interface MyProtocol { }
  • protocol MyProtocol { }
Mark for review

How do you declare a variable in Swift that can hold either an integer or a string?

  • var myVar: Int
  • String
  • var myVar: Any
  • var myVar: Int
Mark for review

Mark for review

How do you declare a generic function in Swift?

  • func myFunction<T>(parameter: T) {}
  • func myFunction<T>(parameter: T)
  • func myFunction(parameter: T) {}
  • func <T>(parameter: T) {}
Mark for review

How do you create a constant array in Swift?

  • let array = [1, 2, 3]
  • var array = [1, 2, 3]
  • const array = [1, 2, 3]
  • let array: [Int] = [1, 2, 3]
Mark for review

What is the correct way to use a for-in loop to iterate over an array in Swift?

  • for item in array { }
  • for (item: array) { }
  • foreach item in array { }
  • for item: array in array { }
Mark for review

What does the static keyword do in Swift?

  • Creates a static property
  • Creates a class method
  • Defines a shared property
  • Defines a type method
Mark for review

What is the output of print("Hello, \(name)") where name is a string variable?

  • Hello, name
  • Hello, (name)
  • Hello, name
  • Hello, name
Mark for review

Which keyword is used to define a class in Swift?

  • class
  • type
  • object
  • structure
Mark for review

What is the default value of an uninitialized variable of type Int in Swift?

  • 0
  • nil
  • 1
  • -1
Mark for review

What keyword is used to define a constant in Swift?

  • var
  • let
  • const
  • static
Mark for review

What does the @objc attribute do in Swift?

  • Makes a Swift method callable from Objective-C
  • Defines an Objective-C class
  • Makes a method private
  • Changes the method signature
Mark for review

How do you declare a constant in Swift that is initialized with a closure?

  • let constant = { return 1 }
  • let constant = { 1 }
  • var constant = { return 1 }
  • let constant = { 1 }
Mark for review

Which collection type in Swift is unordered?

  • Array
  • Dictionary
  • Set
  • List
Mark for review

What is the result of 5 / 2 in Swift?

  • 2.5
  • 2
  • 2.5
  • 3
Mark for review

Which operator is used for optional chaining in Swift?

  • ?
  • !
  • &
  • @
Mark for review

How can you make a Swift function return multiple values?

  • Using tuples
  • Using arrays
  • Using dictionaries
  • Using multiple return statements
Mark for review

How do you handle JSON data in Swift?

  • Using JSONDecoder and JSONEncoder
  • Using JSONParser
  • Using JSONSerializer
  • Using JSONHandler
Mark for review

How do you declare a function in Swift?

  • func myFunction() {}
  • function myFunction() {}
  • declare myFunction() {}
  • def myFunction() {}
Mark for review

What is the purpose of guard statement in Swift?

  • Error handling
  • Conditional checks
  • Function definitions
  • Loops
Mark for review

How can you handle errors in Swift?

  • try-catch
  • handle-error
  • try-catch-finally
  • do-try-catch
Mark for review

Which of the following is a valid Swift comment?

  • // This is a comment
  • # This is a comment
  • <!-- This is a comment -->
  • /** This is a comment */
Mark for review

What is the default access level for properties in a Swift class?

  • private
  • public
  • internal
  • protected
Mark for review

Mark for review

What is the correct way to handle an optional value with a default value in Swift?

  • var value = optionalValue ?? 0
  • var value = optionalValue!
  • var value = optionalValue ?: 0
  • var value = optionalValue
Mark for review

Which keyword allows a Swift class to conform to a protocol?

  • conforms
  • implements
  • :
  • conform
Mark for review

blinkerOnline

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • Answered
  • Not Answered
  • Marked for Review