Online Exam Quiz

questionQuestion  1 to 30

What is the purpose of typealias in Swift?

  • Creates an alias for a type
  • Defines a new type
  • Creates a class alias
  • Defines a type method
Mark for review

How can you specify that a Swift function takes a variable number of arguments?

  • Using varargs
  • Using variadic parameters
  • Using ...
  • Using spread
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 create an immutable dictionary in Swift?

  • let dictionary = ["key": "value"]
  • var dictionary = ["key": "value"]
  • const dictionary = ["key": "value"]
  • let dictionary: [String: String] = ["key": "value"]
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

Which operator is used to concatenate strings in Swift?

  • +
  • &
Mark for review

What keyword is used to define a constant in Swift?

  • var
  • let
  • const
  • static
Mark for review

What does the defer keyword do in Swift?

  • Delays execution until program ends
  • Ensures code is executed after control flow exits
  • Defines a function
  • Changes variable values
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

How can you make a Swift function return multiple values?

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

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

  • private
  • public
  • internal
  • protected
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

Which of the following is used for type casting in Swift?

  • as
  • cast
  • convert
  • type
Mark for review

Mark for review

Which keyword is used to define an enumeration in Swift?

  • enum
  • enumeration
  • enum_type
  • enum_class
Mark for review

Which of the following is a valid Swift variable name?

  • 1stVariable
  • firstVariable
  • first_variable
  • firstVariable
Mark for review

How do you define an optional variable in Swift?

  • var myVar: Int?
  • var myVar: Optional<Int>
  • var myVar: Int!
  • var myVar: Int
Mark for review

Which method is called when a Swift object is deallocated?

  • deinit
  • finalize
  • end
  • destroy
Mark for review

How do you create a tuple in Swift?

  • (1, "A")
  • [1, "A"]
  • {1, "A"}
  • (1; "A")
Mark for review

What type of value does a Swift Bool variable hold?

  • Integer
  • String
  • Boolean
  • Array
Mark for review

How can you handle errors in Swift?

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

Which keyword is used to define a class in Swift?

  • class
  • type
  • object
  • structure
Mark for review

How do you create a read-only property in Swift?

  • var property: Int { get }
  • let property: Int { get }
  • private var property: Int { get }
  • public var property: Int { get }
Mark for review

How do you define a computed property in Swift?

  • var property: Int { get { return 0 } }
  • let property: Int { get { return 0 } }
  • var property: Int { }
  • computed var property: Int { get { return 0 } }
Mark for review

How do you declare a function in Swift?

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

What keyword is used to handle optional values in Swift?

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

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

How do you handle JSON data in Swift?

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

How can you call a method on an optional value safely in Swift?

  • Using optional chaining
  • Using optional unwrap
  • Using forced unwrap
  • Using try-catch
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