Could anyone please help with some Swift programming questions? Question 5 Proto
ID: 3602113 • Letter: C
Question
Could anyone please help with some Swift programming questions?
Question 5
Protocols cannot require specific initializers to be implemented by conforming types.
Question 6
Protocols are types. You can use a protocol in many places where types are allowed.
Question 7
Delegation is a design pattern that enables a class or structure to hand off (or delegate) some of its responsibilities to an instance of another type.
Question 8
RestaurantsViewController is a class that has a superclass called UIViewController. RestaurantsViewController also adopts the protocols UITableViewDataSource and UITableViewDelegate. Which of the following is the correct way to declare the RestaurantsViewController class?
Question 9
A protocol cannot inherit from other protocols.
Question 10
The _________________ operator returns true if an instance conforms to a protocol and returns false if it does not. (See Checking for Protocol Conformance in The Swift Programming Language.)
TrueExplanation / Answer
5)Answer:
False
Explanation:
Protocols can require specific initializers to be implemented by conforming types. You write these initializers as part of the protocol’s definition in exactly the same way as for normal initializers, but without curly braces or an initializer body:
6)Answer:
True
Explanation:
Protocols don’t actually implement any functionality themselves. Nonetheless, any protocol you create will become a fully-fledged type for use in your code.
Because it’s a type, you can use a protocol in many places where other types are allowed, including:
As a parameter type or return type in a function, method, or initializer
As the type of a constant, variable, or property
As the type of items in an array, dictionary, or other container
7)Answer:
True
Explanation:
Delegation is a design pattern that enables a class or structure to hand off (or delegate) some of its responsibilities to an instance of another type. This design pattern is implemented by defining a protocol that encapsulates the delegated responsibilities, such that a conforming type (known as a delegate) is guaranteed to provide the functionality that has been delegated. Delegation can be used to respond to a particular action, or to retrieve data from an external source without needing to know the underlying type of that source.
9)Answer:
False
Explanation:
A protocol can inherit one or more other protocols. The syntax of protocol inheritance is similar to class inheritance.
Suppose there is a struct conforming to the Inheriting protocol, it should also confirm and satisfy all the other protocols that Inheriting protocol inherits from.
10)Answer:
is
Explanation:
The is operator returns true if an instance conforms to a protocol and returns false if it does not. (See Checking for Protocol Conformance in The Swift Programming Language.)