Bird
0
0

What is wrong with this protocol conformance?

medium📝 Debug Q7 of 15
iOS Swift - Swift Language Essentials
What is wrong with this protocol conformance?
protocol Describable {
  func describe() -> String
}

struct Item: Describable {
  func describe() {
    print("Item description")
  }
}
AProtocols cannot require return values
BThe method does not return a String as required
CThe method name is incorrect
DStructs cannot conform to protocols
Step-by-Step Solution
Solution:
  1. Step 1: Check protocol method signature

    The protocol requires 'func describe() -> String', meaning the method must return a String.
  2. Step 2: Check struct method implementation

    The struct implements 'func describe()' with no return type and only prints, which does not satisfy the protocol.
  3. Final Answer:

    The method does not return a String as required -> Option B
  4. Quick Check:

    Return type must match protocol requirement [OK]
Quick Trick: Return types must match protocol exactly [OK]
Common Mistakes:
  • Omitting return type
  • Thinking print satisfies return
  • Believing structs can't conform

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes