Bird
0
0

Which of the following is the correct syntax to declare a protocol named Drivable in Swift?

easy📝 Syntax Q12 of 15
iOS Swift - Swift Language Essentials
Which of the following is the correct syntax to declare a protocol named Drivable in Swift?
Astruct Drivable { func drive() }
Bclass Drivable { func drive() }
Cfunc protocol Drivable() { drive() }
Dprotocol Drivable { func drive() }
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct protocol declaration syntax

    Protocols are declared with the keyword protocol followed by the name and curly braces.
  2. Step 2: Check method declaration inside protocol

    Methods inside protocols are declared without implementation, just the signature.
  3. Final Answer:

    protocol Drivable { func drive() } -> Option D
  4. Quick Check:

    Protocol syntax = keyword 'protocol' + name + method signatures [OK]
Quick Trick: Use 'protocol' keyword, not class or struct [OK]
Common Mistakes:
  • Using class or struct instead of protocol
  • Adding method implementation inside protocol
  • Incorrect keyword order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes